Rounding

  • Thread starter Thread starter Maya
  • Start date Start date
M

Maya

Hi everyone,

How can I round the following decimal figures to 30.54 decimal:

30.540
30.541
30.542
30.543
30.544
30.545
30.546
30.547
30.548
30.549

I know that Math.Floor does that some how, but can't figure out how to
use it to produce 30.54 precisely.

Thanks,

Maya.
 
Thanks Pete, that worked just fine!

Maya.


Since Math.Floor() only return an integer, you need to multiple your  
original number by 100 first, then divide the result by 100 (100m, to  
ensure the result is calculated using the same "decimal" type that you  
started with).

For example:

     decimal number = 30.542

     number = Math.Floor(number * 100) / 100m;

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top