VBScript FormatNumber function
FormatNumber function returns an expression formatted as numbers.
grammar
FormatNumber(Expression[,NumDigAfterDec[,
IncLeadingDig[,UseParForNegNum[,GroupDig]]]])
IncLeadingDig[,UseParForNegNum[,GroupDig]]]])
参数 | 描述 |
---|---|
expression | 必需。需被格式化的表达式。 |
NumDigAfterDec | 可选。指示小数点右侧显示位数的数值。默认值为 -1(使用的是计算机的区域设置)。 |
IncLeadingDig | 可选。指示是否显示小数值的前导零:
|
UseParForNegNum | 可选。指示是否将负值置于括号中:
|
GroupDig | 可选。指示是否使用计算机区域设置中指定的数字分组符号将数字分组:
|
Examples
Example 1
<script type="text/vbscript">
document.write(FormatNumber(20000))
</script>
document.write(FormatNumber(20000))
</script>
Examples of the above output:
20,000.00
try it"
Example 2
Set the number of decimal places:
<script type="text/vbscript">
document.write(FormatNumber(20000,2) & "<br />")
document.write(FormatNumber(20000,5))
</script>
document.write(FormatNumber(20000,2) & "<br />")
document.write(FormatNumber(20000,5))
</script>
Examples of the above output:
20,000.00
20,000.00000
20,000.00000
try it"
Example 3
Whether to display leading zeros for fractional values:
<script type="text/vbscript">
document.write(FormatNumber(.20,,0) & "<br />")
document.write(FormatNumber(.20,,-1))
</script>
document.write(FormatNumber(.20,,0) & "<br />")
document.write(FormatNumber(.20,,-1))
</script>
Examples of the above output:
.20
0.20
0.20
try it"
Example 4
Whether negative values within parentheses:
<script type="text/vbscript">
document.write(FormatNumber(-50,,,0) & "<br />")
document.write(FormatNumber(-50,,,-1))
</script>
document.write(FormatNumber(-50,,,0) & "<br />")
document.write(FormatNumber(-50,,,-1))
</script>
Examples of the above output:
-50.00
(50.00)
(50.00)
try it"
Example 5
Will digital packet:
<script type="text/vbscript">
document.write(FormatNumber(1000000,,,,0) & "<br />")
document.write(FormatNumber(1000000,,,,-1))
</script>
document.write(FormatNumber(1000000,,,,0) & "<br />")
document.write(FormatNumber(1000000,,,,-1))
</script>
Examples of the above output:
1000000.00
1,000,000.00
1,000,000.00
try it"
Complete VBScript Reference