VB中的舍入数

时间:2014-12-27 13:09:34

标签: vb.net rounding

如何将数字舍入为2位小数,例如

12.72 --> 12.70
12.76 --> 12.75

例如

decimal from 1.01 to 1.02 will round off to 1.00
decimal from 1.03 to 1.04 will round off to 1.05
decimal from 1.06 to 1.07 will round off to 1.05
decimal from 1.08 to 1.09 will round off to 1.10

1 个答案:

答案 0 :(得分:0)

你想要做的是舍入到最接近的1/20。所以将数字乘以20,然后除以20:

n = Math.Round(n * 20) / 20