xsy-breeze-ui-rpa > BigNumber > toFormat
BigNumber.toFormat() method
Returns a string representing the value of this BigNumber in normal (fixed-point) notation rounded to decimalPlaces decimal places using rounding mode roundingMode, and formatted according to the properties of the format or FORMAT object.
The formatting object may contain some or all of the properties shown in the examples below.
If decimalPlaces is omitted or is null or undefined, then the return value is not rounded to a fixed number of decimal places.
If roundingMode is omitted or is null or undefined, ROUNDING_MODE is used.
If format is omitted or is null or undefined, FORMAT is used.
Throws if decimalPlaces, roundingMode, or format is invalid.
fmt = {
decimalSeparator: '.',
groupSeparator: ',',
groupSize: 3,
secondaryGroupSize: 0,
fractionGroupSeparator: ' ',
fractionGroupSize: 0
}
x = new BigNumber('123456789.123456789')
// Set the global formatting options
config({ FORMAT: fmt })
x.toFormat() // '123,456,789.123456789'
x.toFormat(3) // '123,456,789.123'
// If a reference to the object assigned to FORMAT has been retained,
// the format properties can be changed directly
fmt.groupSeparator = ' '
fmt.fractionGroupSize = 5
x.toFormat() // '123 456 789.12345 6789'
// Alternatively, pass the formatting options as an argument
fmt = {
decimalSeparator: ',',
groupSeparator: '.',
groupSize: 3,
secondaryGroupSize: 2
}
x.toFormat() // '123 456 789.12345 6789'
x.toFormat(fmt) // '12.34.56.789,123456789'
x.toFormat(2, fmt) // '12.34.56.789,12'
x.toFormat(3, ROUND_UP, fmt) // '12.34.56.789,124'
Signature:
toFormat(decimalPlaces: number, roundingMode: RoundingMode, format?: Format): string;
Parameters
| Parameter | Type | Description |
|---|---|---|
| decimalPlaces | number | |
| roundingMode | RoundingMode | |
| format | Format |
Returns:
string
