https://github.com/writetome51/get-cautiously-rounded
Avoids rounding errors in very large data sets
https://github.com/writetome51/get-cautiously-rounded
javascript numbers rounding typescript
Last synced: 5 months ago
JSON representation
Avoids rounding errors in very large data sets
- Host: GitHub
- URL: https://github.com/writetome51/get-cautiously-rounded
- Owner: writetome51
- License: mit
- Created: 2018-10-03T02:40:06.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-08-03T21:17:04.000Z (over 5 years ago)
- Last Synced: 2025-08-09T00:35:47.849Z (5 months ago)
- Topics: javascript, numbers, rounding, typescript
- Language: TypeScript
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# getCautiouslyRounded(number): number
This function avoids cumulative rounding errors only by changing rounding rules in
one area -- when the fraction part of `number` is .5
## Examples
```js
getCautiouslyRounded(2.5); // --> 2
getCautiouslyRounded(3.5); // --> 4
getCautiouslyRounded(-2.5); // --> -2
getCautiouslyRounded(-3.5); // --> -4
// In all other cases, it rounds the normal way you expect.
getCautiouslyRounded(2.7); // --> 3
getCautiouslyRounded(-2.7); // --> -3
getCautiouslyRounded(3.2); // --> 3
```
## Installation
`npm i @writetome51/get-cautiously-rounded`
## Loading
```js
import { getCautiouslyRounded } from '@writetome51/get-cautiously-rounded';
```