@akmjenkins/nearest
v1.0.3
Published
Round to a nearest N
Downloads
17
Readme
@akmjenkins/nearest
Rounds a number to the nearest N
import nearest from '@akmjenkins/nearest';
const roundToNearest10 = nearest(10);
roundToNearest10(5); // 10
roundToNearest10(4); // 0
const roundUpToNearest10 = nearest(10,Math.ceil);
roundUpToNearest10(5); // 10
roundUpToNearest10(1); // 10
roundUpToNearest10(11); // 20
const 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
)
<script src="https://unpkg.com/@akmjenkins/nearest">
const roundToNearest10 = nearest(10);
roundToNearest10(5); // 10
</script>