2014-05-15 21:43:08 +02:00

49 lines
1.2 KiB
Markdown

# Function format
Format a value of any type into a string.
## Syntax
```js
math.format(value)
math.format(value, options)
math.format(value, precision)
math.format(value, fn)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`value` | * | Value to be stringified
`options` | Object | Function | Number | Formatting options
### Returns
Type | Description
---- | -----------
String | str The formatted value
## Examples
```js
math.format(6.4); // returns '6.4'
math.format(1240000); // returns '1.24e6'
math.format(1/3); // returns '0.3333333333333333'
math.format(1/3, 3); // returns '0.333'
math.format(21385, 2); // returns '21000'
math.format(12.071, {notation: 'fixed'}); // returns '12'
math.format(2.3, {notation: 'fixed', precision: 2}); // returns '2.30'
math.format(52.8, {notation: 'exponential'}); // returns '5.28e+1'
```
## See also
[print](print.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->