抱歉很难表述。
我需要像这样四舍五入:
12 -> 10
152 -> 200
1538 -> 2000
25000 -> 30000
etc.
绞尽脑汁,但不知道该怎么做。必须适用于任意 n 个数字。任何人都有一个优雅的方法吗?
c# 或 vb.net
最佳答案
这个怎么样:
double num = 152;
int pow = (int)Math.Log10(num);
int factor = (int)Math.Pow(10, pow);
double temp = num / factor;
double result = Math.Round(temp) * factor;
关于c# - 将任何 n 位数字四舍五入为 (n-1) 个零位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4601228/