I have this rounding where I am trying to round the decimal price so that the decimals always round to either .00 or .05 (using this rule .00,.01,.02,.03,.04 = .00 and .05,.06,.07,.08,.09 = .05) – but right now with the below code it also returns .01, .02 etc in the decimal numbers.
// 2 is the number of decimals that it should return.
decimal unitPriceFloored = System.Math.Round(price, 2, System.MidpointRounding.ToZero);
How can I change it so that it round the price to .00 or .05 in the decimals?
Just to clarify – this should work the same way with .10 and .15 etc. (all 2 decimal comma numbers)
2
Answers
I don’t know of a built-in function to do this. Here’s a way:
This prints:
This should work:
PS: Still have to get used to stackoverflow formatting,sorry …
Results are the following:
1->1
1.01->1.0
1.02->1
1.03->1
1.04->1
1.05->1.05
1.06->1.05
1.07->1.05
1.08->1.05
1.09->1.05
1.1-<1.1
2->2
Now it should work 😀