https://github.com/drag13/roundto
Small function that rounds number with selected precision
https://github.com/drag13/roundto
javscript math round rounding
Last synced: about 1 year ago
JSON representation
Small function that rounds number with selected precision
- Host: GitHub
- URL: https://github.com/drag13/roundto
- Owner: Drag13
- License: mit
- Created: 2018-06-21T08:33:42.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T02:43:00.000Z (over 3 years ago)
- Last Synced: 2025-03-13T18:42:17.612Z (over 1 year ago)
- Topics: javscript, math, round, rounding
- Language: JavaScript
- Size: 151 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# RoundTo
[](https://codecov.io/gh/Drag13/RoundTo)
[](https://travis-ci.org/Drag13/RoundTo)
[](https://www.npmjs.com/package/@drag13/round-to)
[](https://github.com/Drag13/RoundTo)
[](https://github.com/Drag13/RoundTo/blob/master/LICENSE)
## Description
Small one-function-lib to round numbers with custom precision. TypeScript ready.
## Installation
`npm install @drag13/round-to`
## Usage
RoundTo function rounds your decimal with selected precesion. It also tries to handle edge cases with floating point using Epsilon shift and nano-robots.
``` javascript
const round = require('@drag13/round-to');
const roundingResult = round(5.4399, 2);
console.assert(roundingResult===5.44);
```
## TypeScript
Feel free to use it with TypeScript
``` typescript
import * as round from '@drag13/round-to';
const roundingResult = round(5.4399, 2);
console.assert(roundingResult===5.44);
```
## Tests
`npm test`
## Some covered cases
```javascript
console.assert(roundTo(0.43499999999999994, 2)===0.435);
console.assert(roundTo(Math.PI, 2)===3.14);
```
## Contributing
Any bug fixing is appreciated. If you want to add new functionality - you're welcome. But KISS it please.