Number Utilities
A collection of various number-related utility functions.
Installation
Install the package with NPM:
npm install @donutteam/number-utilities
Usage
centsToUSD
Takes an amount of cents and formats it as an amount of US dollars.
import { centsToUSD } from "@donutteam/number-utilities";
const myDollars = centsToUSD(4320);
dollarsToUSD
Takes an amount of dollars and formats it as an amount of US dollars.
import { dollarsToUSD } from "@donutteam/number-utilities";
const myDollars = dollarsToUSD(43.20);
randomInt
Generates a random integer between the minimum (inclusive) and the maximum (exclusive) values given to it:
import { randomInt } from "@donutteam/number-utilities";
const myRandomInteger = randomInt(0, 10);
roundToNearestMultiple
Rounds a number to the nearest multiple of the other number.
import { roundToNearestMultiple } from "@donutteam/number-utilities";
const myRoundedNumber = roundToNearestMultiple(457, 50);
roundDownToNearestMultiple
Rounds a number down to the nearest multiple of the other number.
import { roundDownToNearestMultiple } from "@donutteam/number-utilities";
const myRoundedNumber = roundDownToNearestMultiple(499, 50);
roundUpToNearestMultiple
Rounds a number up to the nearest multiple of the other number.
import { roundUpToNearestMultiple } from "@donutteam/number-utilities";
const myRoundedNumber = roundUpToNearestMultiple(457, 50);
License
MIT