https://github.com/alvarocastro/round
Round values up to an amount of decimals
https://github.com/alvarocastro/round
float floating-point math round
Last synced: over 1 year ago
JSON representation
Round values up to an amount of decimals
- Host: GitHub
- URL: https://github.com/alvarocastro/round
- Owner: alvarocastro
- License: mit
- Created: 2020-03-30T21:09:15.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-25T07:05:59.000Z (over 3 years ago)
- Last Synced: 2024-04-14T06:55:58.545Z (about 2 years ago)
- Topics: float, floating-point, math, round
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/@alvarocastro/round
- Size: 1.2 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Round
[](https://www.npmjs.com/package/@alvarocastro/round)
[](https://github.com/alvarocastro/round/actions?query=workflow%3Abuild)
[](https://codeclimate.com/github/alvarocastro/round/maintainability)
[](https://coveralls.io/github/alvarocastro/round?branch=master)
[](https://bundlephobia.com/result?p=@alvarocastro/round)
[](https://github.com/xojs/xo)
[](https://github.com/semantic-release/semantic-release)
Round values up to an amount of decimals, avoiding the floating point weirdness of JavaScript.
- [Install](#install)
- [Usage](#usage)
- [Contributing](#contributing)
- [Support](#support)
## Install
```bash
npm install @alvarocastro/round
```
## Usage
```js
const round = require('@alvarocastro/round');
round(1.005);
// => 1.01
round(2.2222, 1);
// => 1.1
round(3, 5);
// => 3
```
### round(number[, decimals = 2])
Returns the value rounded up to a given amout of decimals.
#### number
Type: `Number`
Value to round.
#### decimals
Type: `Number`
Default: 2
The amount of decimals to round the number to.
## Contributing
Contributions are always welcome! Please run `npm test` beforehand to ensure everything is ok.
## Support
If you use this package please consider starring it :)