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
 
Back
Top