@spa-tools/utilities
formatFloat()
The formatFloat()
function formats a number as a float with the
specified number of decimal places optional grouping with additional
option of how to handle negative numbers.
Usage
import { formatFloat } from '@spa-tools/utilities';
const formatted1 = formatFloat(1234.5678, 2, false);
console.log(formatted1);
// --> 1234.57
const formatted2 = formatFloat(90123456.78951, 3, true);
console.log(formatted2);
// --> 90,123,456.790
const formatted3 = formatFloat(-123456789.123456, 4, true, true);
console.log(formatted3);
// --> (123,456,789.1235)
Arguments
Name | Type | Required? | Default | Description |
---|---|---|---|---|
value | number | yes | - | The value to format |
decimalPlaces | number | no | 2 | The number of decimal places to round to |
useGrouping | boolean | no | true | Determines whether or not to add grouping (,)s to result |
parentheticalNegatives | boolean | no | false | Determines whether or not to use parentheses for negative numbers instead of - sign |
Returns
Returns formatted float.