Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/devgru/round-to-unit
Number-rounding and formatting library with focus on correct string representation. roundToUnit('0.25')(0.4) === '0.50'
https://github.com/devgru/round-to-unit
precision rounding
Last synced: 4 days ago
JSON representation
Number-rounding and formatting library with focus on correct string representation. roundToUnit('0.25')(0.4) === '0.50'
- Host: GitHub
- URL: https://github.com/devgru/round-to-unit
- Owner: devgru
- License: mit
- Created: 2015-11-11T19:35:29.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2024-04-21T20:08:03.000Z (7 months ago)
- Last Synced: 2024-10-31T19:49:21.506Z (17 days ago)
- Topics: precision, rounding
- Language: JavaScript
- Homepage:
- Size: 11.7 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# round-to-unit
> Number-rounding and formatting library with focus on correct string representation. Useful in user interfaces and data visualizations.
This library provides rounding function converting raw user input (e.g. pointer coordinates) into nice values that are multiples to specified `unit`.
By default, library outputs strings. This behaviour can be overridden.
## Usage
```js
import { roundToUnit } from 'round-to-unit';const roundToQuarters = roundToUnit('0.25');
roundToQuarters(-0.7); // "-0.75"const roundToTenths = roundToUnit('0.1', Number);
roundToTenths(0.36); // 0.4
```## NPM package
Install `round-to-unit@2`, it has no dependencies.
## API Reference
`roundToUnit(unit, [outputType = String])`
Given a string representing positive finite number `unit`, returns a `roundToSpecifiedUnit` function.
Provide optional `outputType` to override return type of `roundToSpecifiedUnit` function.
`roundToSpecifiedUnit(input)`
Given a number `input`, rounds it to specified `unit` and transforms it to `outputType`.
## Development
* Build `bun run prepack`;
* Run tests: `bun test`;## License
MIT © [Dima Semyushkin](https://devg.ru)