https://github.com/gapitio/gapit-format-si
Format a number into SI metric prefixed value.
https://github.com/gapitio/gapit-format-si
converts format-si metric-prefix utility
Last synced: about 2 months ago
JSON representation
Format a number into SI metric prefixed value.
- Host: GitHub
- URL: https://github.com/gapitio/gapit-format-si
- Owner: gapitio
- Created: 2020-10-09T12:47:39.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T15:10:54.000Z (over 3 years ago)
- Last Synced: 2025-10-26T00:48:37.547Z (8 months ago)
- Topics: converts, format-si, metric-prefix, utility
- Language: TypeScript
- Homepage:
- Size: 1.28 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# Format SI
Format a number into [SI metric prefixed value](https://en.wikipedia.org/wiki/Metric_prefix).
## Usage
There are three different functions that converts a value into SI metric prefixed value.
### formatSI()
Converts a number into the metric prefixed value.
Example:
```ts
formatSI(10000, "W"); // Returns { value: 10, unit: "kW" }
```
### formatFixedSI()
Uses [formatSI()](#format-si) to convert the number, but it adds [.toFixed(fractionDigits)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed) to the value.
Example:
```ts
formatFixedSI(10000 "W", 3,); // Returns { value: "10.000", unit: "kW" }
```
### formatPrecisionSI()
Uses [formatSI()](#format-si) to convert the number, but it adds [.toPrecision(precision)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Number/toPrecision) to the value.
Example:
```ts
formatPrecisionSI(10000 "W", 3,); // Returns { value: "10.0", unit: "kW" }
```