money round

S

Steph

hello,
a little problem :
i must do a round number from : 1.125 $ (1 dollar 125)
but Math.Round(1.125, 2) = 1.12 and not 1.13 ...
how do ?

actually i use : Math.Round(1.125+0.0000001, 2) but its not really clean...

thanks
 
J

Jon Skeet [C# MVP]

Steph said:
a little problem :
i must do a round number from : 1.125 $ (1 dollar 125)
but Math.Round(1.125, 2) = 1.12 and not 1.13 ...
how do ?

actually i use : Math.Round(1.125+0.0000001, 2) but its not really clean...

Use an overload of Math.Round which takes a MidpointRounding parameter.
Oh, and stop using double to represent money - use decimal instead.
 
S

Steph

Jon said:
Use an overload of Math.Round which takes a MidpointRounding parameter.
Oh, and stop using double to represent money - use decimal instead.
thanks
 

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

Top