array split
介绍 (Introduction)
关于最近的一个问题,我提供了一个简单的函数来格式化带后缀的数字,以表示其大小(MB,GB,TB等)。 虽然功能很简单,但我想知道是否提供了最有效的代码。 本文比较了Array()和Split()函数的性能。()
The Problem
The question (问题
问题( http:Q_28494315.html) stated a need to add the scale suffix to a number. Excel did not provide the ability to format cell values this way and conditional formatting does not affect the cell's value. The cell still contains a numeric value, while Excel displays the formatted value. http:Q_28494315.html )表示需要在数字后加上小数位数后缀。 Excel没有提供以这种方式格式化单元格值的功能,并且条件格式设置不会影响单元格的值。 单元格仍包含数字值,而Excel显示格式化的值。()
Example:
例:
12345600 = 12.3456 MB
12345600 = 12.3456 MB
1234560000 = 1.23456 GB
1234560000 = 1.23456 GB
()
The Accepted and Alternative Solutions
Since there were only three possible suffixes, the conditional formatting solution was the simplest and the one accepted as the question solution.公认的和替代的解决方案
由于只有三个可能的后缀,因此条件格式解决方案是最简单的,而一个被接受为问题解决方案。[>999999999999]0.00,,,,"TB";[>999999999]0.00,,,"GB";0.00,,"MB"
()
The User-Defined Function Solutions
Let's start with a routine that uses an Array() function, most closely resembling the question's solution. If the magnitude of the parameter value is greater than 1000, we use the base1000 log of the number to index into the Array() values.用户定义的功能解决方案
让我们从使用Array()函数的例程开始,该例程最类似于问题的解决方案。 如果参数值的大小大于1000,则使用数字的base1000对数来索引Array()值。