Converts a Number
into a String
with a plus or minus sign.
nfp()
converts numbers such as 123 into strings formatted with a +
or -
symbol to mark whether they're positive or negative, as in '+123'
.
The first parameter, num
, is the number to convert to a string. For example, calling nfp(123.45)
returns the string '+123.45'
. If an array of numbers is passed, as in nfp([123.45, -6.78])
, an array of formatted strings will be returned.
The second parameter, left
, is optional. If a number is passed, as in nfp(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 nfp(123.45, 4)
returns the string '+0123.45'
.
The third parameter, right
, is also optional. If a number is passed, as in nfp(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 nfp(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 nfp(123.45, 4, 3)
returns the string '+0123.450'
.
उदाहरण
सिंटैक्स
nfp(num, [left], [right])
nfp(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.