mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-18 14:59:29 +00:00
46 lines
1.1 KiB
Markdown
46 lines
1.1 KiB
Markdown
# Function format
|
|
|
|
Format a value of any type into a string.
|
|
|
|
|
|
## Syntax
|
|
|
|
```js
|
|
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
|
|
|
|
```js
|
|
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'
|
|
```
|
|
|
|
|
|
|
|
|
|
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
|