Is there any way to round up decimal value to its nearest 0.05 value in .Net?
Ex:
7.125 -> 7.15
6.66 -> 6.7
If its now available can anyone provide me the algo?
Select cell A2 in the worksheet to enter this cell reference as the number argument. Select the Multiple line. Type in 0.05 so that the number in cell A2 will be rounded up or down to the nearest multiple of 5 cents. Select Done to return to the worksheet.
Whenever the value right after the decimal is less than 5, we round down; otherwise, we round up.
How about:
Math.Ceiling(myValue * 20) / 20
Use this:
Math.Round(mydecimal / 0.05m, 0) * 0.05m;
The same logic can be used in T-SQL:
ROUND(@mydecimal / 0.05, 0) * 0.05
I prefer this approach to the selected answer simply because you can directly see the precision used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With