1.1 KiB

Function format

Format a value of any type into a string.

Syntax

format(value)
format(value, options)
format(value, precision)
format(value, fn)

Parameters

Parameter Type Description
value * Value to be stringified
options Object | Function | Number

Returns

Type Description
String str The formatted value

Examples

format(6.4);                                        // '6.4'
format(1240000);                                    // '1.24e6'
format(1/3);                                        // '0.3333333333333333'
format(1/3, 3);                                     // '0.333'
format(21385, 2);                                   // '21000'
format(12.071, {notation: 'fixed'});                // '12'
format(2.3,    {notation: 'fixed', precision: 2});  // '2.30'
format(52.8,   {notation: 'exponential'});          // '5.28e+1'