https://github.com/nick-lai/round-decimal
Decimal rounding with ULP.
https://github.com/nick-lai/round-decimal
decimal library math places precision round round-decimal rounding ulp
Last synced: 5 months ago
JSON representation
Decimal rounding with ULP.
- Host: GitHub
- URL: https://github.com/nick-lai/round-decimal
- Owner: nick-lai
- License: mit
- Created: 2022-11-13T06:20:19.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-22T12:34:46.000Z (about 2 years ago)
- Last Synced: 2025-10-01T16:27:55.536Z (9 months ago)
- Topics: decimal, library, math, places, precision, round, round-decimal, rounding, ulp
- Language: TypeScript
- Homepage:
- Size: 68.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/funding.yml
- License: LICENSE
Awesome Lists containing this project
README
# round-decimal
[](https://github.com/nick-lai/round-decimal/actions/workflows/codeql.yml)
[](https://github.com/nick-lai/round-decimal/actions/workflows/test.yml)
[](https://coveralls.io/github/nick-lai/round-decimal?branch=main)
[](https://www.npmjs.com/package/round-decimal)
[](https://bundlephobia.com/package/round-decimal)
Decimal rounding with [ULP](https://w.wiki/5xCp).
> **Warning**
> Work in process
## Installation
### NPM
```bash
npm install -D round-decimal
```
### CDN
#### jsDelivr
Load `roundDecimal` from [jsDelivr](https://www.jsdelivr.com/package/npm/round-decimal).
```html
```
#### unpkg
Load `roundDecimal` from [unpkg](https://unpkg.com/round-decimal/dist/).
```html
```
## Usage
### Syntax
```javascript
roundDecimal(value, minSignificantFractionDigits = 3)
```
### Description
Decimal rounding with [ULP](https://w.wiki/5xCp).
### Parameters
- `value`
- A number.
- `minSignificantFractionDigits`
- Minimum significant fraction digits.
- Default: `3`
### Return value
The rounded value.
### Examples
```javascript
import roundDecimal from 'round-decimal';
console.log(0.1 + 0.2); // 0.30000000000000004
console.log(roundDecimal(0.1 + 0.2)); // 0.3
console.log(-0.1 - 0.2); // -0.30000000000000004
console.log(roundDecimal(-0.1 - 0.2)); // -0.3
console.log(10000000000.1 + 10000000000.2); // 20000000000.300003
console.log(roundDecimal(10000000000.1 + 10000000000.2)); // 20000000000.3
console.log(roundDecimal(10000000000.1 + 10000000000.2, 6)); // 20000000000.300003
console.log(10000000000000.1 + 10000000000000.2); // 20000000000000.297
console.log(roundDecimal(10000000000000.1 + 10000000000000.2)); // 20000000000000.297
console.log(roundDecimal(10000000000000.1 + 10000000000000.2, 2)); // 20000000000000.3
console.log(roundDecimal(1.3549999999999998)); // 1.355
```
Try it out on [JSFiddle](https://jsfiddle.net/nick_lai/h09dfL5o/).
## License
[MIT](https://github.com/nick-lai/round-decimal/blob/main/LICENSE)