logo

Number

This is a collection of functions for working with numbers.

Get the absolute value

The getAbsoluteNumber function returns the absolute value of a number.

import { getAbsoluteNumber } from '@aracna/core';

// will log 1
console.log(getAbsoluteNumber(-1));

Limit the number of decimals

The getFixedNumber function returns a number with a fixed number of decimals.

import { getFixedNumber } from '@aracna/core';

// will log 2.5
console.log(getFixedNumber(2.51, 1));

Get the distance between two numbers

The getNumbersDistance function returns the distance between two numbers.

import { getNumbersDistance } from '@aracna/core';

// will log 2
console.log(getNumbersDistance(3, 5));

Limit the number between a minimum and a maximum

The getLimitedNumber function returns a number between a minimum and a maximum.

import { getLimitedNumber } from '@aracna/core';

// will log 3
console.log(getLimitedNumber(5, { max: 3 }));

Calculate the percentage

The getNumberPercentage function returns the percentage of a number. Optionally the percentage can be rounded.

import { getNumberPercentage } from '@aracna/core';

// will log 75%
console.log(getNumberPercentage(75));

Get the highest number in an array

The getHighestNumber function returns the highest number in an array of numbers.

import { getHighestNumber } from '@aracna/core';

// will log 2
console.log(getHighestNumber(0, 1, 2));

Get the lowest number in an array

The getLowestNumber function returns the lowest number in an array of numbers.

import { getLowestNumber } from '@aracna/core';

// will log 0
console.log(getLowestNumber(0, 1, 2));

Parse an unknown value to a bigint

The parseBigInt function returns a bigint from an unknown value.

import { parseBigInt } from '@aracna/core';

// will log 1n
console.log(parseBigInt('1'));

Parse an unknown value to a number

The parseNumber function returns a number from an unknown value.

import { parseNumber } from '@aracna/core';

// will log 5
console.log(parseNumber('5'));

// will log 2.5
console.log(parseNumber('2.5'));

Check if a number is even

The isNumberEven function checks if a number is even.

import { isNumberEven } from '@aracna/core';

// will log true
console.log(isNumberEven(0));

Check if a number is odd

The isNumberOdd function checks if a number is odd.

import { isNumberOdd } from '@aracna/core';

// will log true
console.log(isNumberOdd(1));

Check if a number is multiple of another

The isNumberMultipleOf function checks if a number is multiple of another number.

import { isNumberMultipleOf } from '@aracna/core';

// will log true
console.log(isNumberMultipleOf(4, 2));