https://github.com/akmjenkins/nearest
Round to the nearest N
https://github.com/akmjenkins/nearest
Last synced: about 1 month ago
JSON representation
Round to the nearest N
- Host: GitHub
- URL: https://github.com/akmjenkins/nearest
- Owner: akmjenkins
- Created: 2021-06-25T22:04:02.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-06-26T17:34:01.000Z (almost 4 years ago)
- Last Synced: 2025-03-17T19:53:23.087Z (about 1 month ago)
- Language: JavaScript
- Size: 194 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# @akmjenkins/nearest
[](https://npmjs.org/package/@akmjenkins/nearest)
[](https://coveralls.io/github/akmjenkins/nearest)
[](https://travis-ci.com/akmjenkins/nearest)
[](https://bundlephobia.com/result?p=@akmjenkins/nearest)## Rounds a number to the nearest N
```js
import nearest from '@akmjenkins/nearest';const roundToNearest10 = nearest(10);
roundToNearest10(5); // 10
roundToNearest10(4); // 0const roundUpToNearest10 = nearest(10,Math.ceil);
roundUpToNearest10(5); // 10
roundUpToNearest10(1); // 10
roundUpToNearest10(11); // 20const roundDownToNearest10 = nearest(10,Math.floor);
roundDownToNearest10(5); // 0
roundDownToNearest10(1); // 0
roundDownToNearest10(11); // 10
roundDownToNearest10(19); // 10
```Or in the browser (creates a global `nearest`)
```html
const roundToNearest10 = nearest(10);
roundToNearest10(5); // 10```