$u.n.toStr Function
Syntax
Arguments
- valuenumber
The numeric value to format into a string.
- decimalPlacenumber
The number of decimal places to round the number.
- formatstring
Format flags indicating how to format the value. Available format flags are:
- Format Flag
- Definition
- B
Return a blank string if the number equals "0".
- ,
Include a thousands separator. The default string used as a thousands separator is a comma ",". The thousands separator used is defined in $u.comma. You can change the thousands separator to any string you desire.
- -
Use a "-" before the number if it is negative.
- (
Bracket the number in parentheses if it is negative.
- prefixstring
A prefix that should be prepended to the string.
- suffixstring
A suffix that should be appended to the string.
Description
Convert a number into a string.
Example
var value = 11222.152; var decimalPlace = 2; var format = ","; var prefix = "$"; var suffix = "(US)"; var string1 = $u.n.toStr(value, decimalPlace, format, prefix, suffix); /* string1 is: '$11,222.15 (US)'*/ value = -11222.152; format = "(,"; var string2 = $u.n.toStr(value, decimalPlace, format, prefix, suffix); /* string2 is: '($11,222.15 (US))'*/
Thousands Separator and Decimal Character
The default value for the thousands separator and decimal character are a comma "," and period ".", respectively. These values can be changed using the $u.comma and $u.decimal properties. EG:
// Set the thousands separator to a period: $u.comma = "."; // Set the decimal to a comma: $u.decimal = ","; var value = 11222.152; var decimalPlace = 2; var format = ","; // Format the value: var string3 = $u.n.toStr(value, decimalPlace, format); /* string3 is : '11.222,15' */