我需要一个公式,根据数字是数十,数百,数千,数十,数百万等不同来对数字进行舍入.我知道Excel中的基本舍入函数但不确定如何准确地执行此操作.
例子:
1 - 999 need to be rounded up to the nearest 10.
1.000 - 99.999 need to be rounded up to the nearest 100.
100.000 - 999.999 need to be rounded up to the nearest 1.000.
1.000.000 - 999.999.999 need to be rounded up to the nearest 100.000.
1.000.000.000 - 999.999.999.999 need to be rounded up to the nearest 1.000.000
Run Code Online (Sandbox Code Playgroud)
所有这一切都在单一的公式中,可以很容易地被复制下来.
任何帮助将不胜感激!
您可以使用ROUNDUP具有LOOKUP嵌套功能的函数来为您提供所需的逻辑,即使用A2中的值向下使用此公式在B2中复制下来
=ROUNDUP(A2,LOOKUP(A2,10^{0,3,5,6,9},-{1,2,3,5,6}))
这部分
10^{0,3,5,6,9}
定义每个范围的下限.而这部分:
-{1,2,3,5,6}
给出舍入到的位数,例如-2给下一个100,-3给下一个1000等.
这会向上舍入到最近的100等的倍数.所以134将舍入到140.如果要舍入到最接近的倍数,那么您可以使用完全相同的公式但ROUND代替ROUNDUP