Converts a positive Number
into a String
with an extra space in front.
nfs()
converts positive numbers such as 123.45 into strings formatted with an extra space in front, as in ' 123.45'. Doing so can be helpful for aligning positive and negative numbers.
The first parameter, num
, is the number to convert to a string. For example, calling nfs(123.45)
returns the string ' 123.45'
.
The second parameter, left
, is optional. If a number is passed, as in nfs(123.45, 4)
, it sets the minimum number of digits to include to the left of the decimal place. If left
is larger than the number of digits in num
, then unused digits will be set to 0. For example, calling nfs(123.45, 4)
returns the string ' 0123.45'
.
The third parameter, right
, is also optional. If a number is passed, as in nfs(123.45, 4, 1)
, it sets the minimum number of digits to include to the right of the decimal place. If right
is smaller than the number of decimal places in num
, then num
will be rounded to the given number of decimal places. For example, calling nfs(123.45, 4, 1)
returns the string ' 0123.5'
. If right
is larger than the number of decimal places in num
, then unused decimal places will be set to 0. For example, calling nfs(123.45, 4, 3)
returns the string ' 0123.450'
.
示例
语法
nfs(num, [left], [right])
nfs(nums, [left], [right])
参数
number to format.
number of digits to include to the left of the decimal point.
number of digits to include to the right of the decimal point.
numbers to format.