0

I would like to format decimal numbers to the NEXT 0.10 cents (dime) in C# like so:

22.62 -> 22.70
23.50 -> 22.50
23.21 -> 23.30
23.03 -> 23.10
23.10 -> 23.10
23.14 -> 23.20
23.17 -> 23.20
23.11 -> 23.20

Any help would be appreciated. Thanks

What I have so far:

Math.Round(22.621, 1, MidpointRounding.AwayFromZero) //gives 22.60 
Math.Round(22.656, 1, MidpointRounding.AwayFromZero) //gives 22.70 
Kevin Vella
  • 1,869
  • 1
  • 16
  • 18

1 Answers1

4

This method will get the answer you're looking for:

decimal RoundToNextDime(decimal d)
{
    return Math.Ceiling(d*10)/10;
}
Tim S.
  • 55,448
  • 7
  • 96
  • 122