money round

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steph

    money round

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

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

    thanks
  • Peter Duniho

    #2
    Re: money round

    On Thu, 27 Mar 2008 08:37:46 -0700, Steph <steph@pipoland .comwrote:
    hello,
    a little problem :
    i must do a round number from : 1.125 $ (1 dollar 125)
    but Math.Round(1.12 5, 2) = 1.12 and not 1.13 ...
    how do ?
    Just use one of the overloads for Math.Round() that allows you to specify
    the MidpointRoundin g mode.

    Pete

    Comment

    • Steph

      #3
      Re: money round

      Jon Skeet [C# MVP] wrote:
      Steph <steph@pipoland .comwrote:
      >a little problem :
      >i must do a round number from : 1.125 $ (1 dollar 125)
      >but Math.Round(1.12 5, 2) = 1.12 and not 1.13 ...
      >how do ?
      >>
      >actually i use : Math.Round(1.12 5+0.0000001, 2) but its not really clean...
      >
      Use an overload of Math.Round which takes a MidpointRoundin g parameter.
      Oh, and stop using double to represent money - use decimal instead.
      >
      thanks

      Comment

      Working...