NumWiz
The ultimate number utility library for JavaScript & TypeScript — arithmetic, formatting, currency, number-to-words in 10 languages, statistics, financial math, matrix algebra, and much more.
Table of Contents
Installation
Quick Start
Architecture
Chainable API — numwiz()
Static Modules
Subpath Imports
Supported Locales
TypeScript Support
Error Reference
Installation
Quick Startimport numwiz, { Arithmetic, Formatting, Statistics, Matrix } from "numwiz" ;
numwiz ( 1234567 ) . toCommas ( ) ;
numwiz ( 1000000 ) . locale ( "hi" ) . toWords ( ) ;
numwiz ( 50 ) . add ( 50 ) . multiply ( 2 ) . abbreviate ( ) ;
Arithmetic. add ( 1 , 2 , 3 , 4 ) ;
Formatting. toWords ( 1000000 , "en" , "indian" ) ;
Statistics. mean ( [ 1 , 2 , 3 , 4 , 5 ] ) ;
Matrix. determinant ( [
[ 1 , 2 ] ,
[ 3 , 4 ] ,
] ) ;
ArchitectureNumWiz exposes two parallel patterns:
Pattern
How to use
Best for
Chainable numwiz(n)
numwiz(100).add(50).toCommas()
Fluent transformations on a single number
Static modules
Arithmetic.add(1, 2, 3)
Direct one-off calls, tree-shakeable imports
All static methods are pure and non-mutating — inputs are never modified.
Chainable API — numwiz() Importimport numwiz from "numwiz" ;
const { numwiz } = require ( "numwiz" ) ; Basic Exampleconst result = numwiz ( 9876543 ) . add ( 123457 ) . multiply ( 2 ) . abbreviate ( ) ;
numwiz ( 1500000 ) . locale ( "hi" ) . system ( "indian" ) . toWords ( ) ;
numwiz ( 99.5 ) . round ( 0 ) . toCurrency ( "USD" ) ;
Arithmetic MethodsAll arithmetic methods update the internal value in-chain and return this.
Method
Description
Example
.add(n)
Add n
numwiz(10).add(5).val() → 15
.subtract(n)
Subtract n
numwiz(10).subtract(3).val() → 7
.multiply(n)
Multiply by n
numwiz(4).multiply(3).val() → 12
.divide(n)
Divide by n
numwiz(10).divide(2).val() → 5
.mod(n)
Modulo n
numwiz(10).mod(3).val() → 1
.power(n)
Raise to power n
numwiz(2).power(8).val() → 256
.sqrt()
Square root
numwiz(9).sqrt().val() → 3
.cbrt()
Cube root
numwiz(27).cbrt().val() → 3
.abs()
Absolute value
numwiz(-5).abs().val() → 5
.negate()
Negate
numwiz(5).negate().val() → -5
.floor()
Floor
numwiz(4.9).floor().val() → 4
.ceil()
Ceiling
numwiz(4.1).ceil().val() → 5
.trunc()
Truncate toward zero
numwiz(4.9).trunc().val() → 4
.round(decimals?)
Round to decimal places
numwiz(3.14159).round(2).val() → 3.14
.clamp(min, max)
Clamp to range
numwiz(150).clamp(0, 100).val() → 100
.percent(p)
p% of value
numwiz(200).percent(15).val() → 30
ConfigurationThese chainable setters affect how output methods behave. Each returns this.
Method
Description
Example
.locale(code)
Set locale for words/ordinals
.locale("hi"), .locale("fr")
.system("western"|"indian")
Number scale for words
.system("indian") uses lakh/crore
.currency(code)
Default currency code
.currency("INR")
.safe()
Enable safe mode on an existing chain
See Safe Mode
Output MethodsThese are terminal — they return a plain value (not this).
Raw value
Method
Returns
Description
.val()
number
Current numeric value
.result()
number
Alias for val()
.valueOf()
number
Native coercion hook
.toString()
string
String representation
.isValid()
boolean
false if value is NaN or non-finite
Method
Returns
Example
.toFixed(d?)
number
numwiz(3.14159).toFixed(2) → 3.14
.toCommas()
string
numwiz(1234567).toCommas() → "1,234,567"
.toIndianCommas()
string
numwiz(1234567).toIndianCommas() → "12,34,567"
.toRoman()
string
numwiz(2026).toRoman() → "MMXXVI"
.toFraction(maxDenom?)
string
numwiz(0.333).toFraction() → "1/3"
.toScientific(d?)
string
numwiz(12345).toScientific(2) → "1.23e+4"
.toEngineering()
string
numwiz(12345).toEngineering() → "12.345×10^3"
.toPercentage(d?)
string
numwiz(75).toPercentage() → "75.00%"
.ratioToPercentage(d?)
string
numwiz(0.75).ratioToPercentage() → "75.00%"
.toOrdinal()
string
numwiz(3).locale("en").toOrdinal() → "3rd"
.abbreviate(d?)
string
numwiz(1500000).abbreviate() → "1.5M"
.abbreviateIndian(d?)
string
numwiz(1500000).abbreviateIndian() → "15L"
Words
Method
Returns
Notes
.toWords()
string
Uses current .locale() and .system() settings
.toWordsWestern()
string
Forces western scale (million/billion)
.toWordsIndian()
string
Forces Indian scale (lakh/crore)
numwiz ( 1000000 ) . locale ( "en" ) . toWords ( ) ;
numwiz ( 1000000 ) . locale ( "en" ) . toWordsIndian ( ) ;
numwiz ( 1000000 ) . locale ( "hi" ) . toWordsIndian ( ) ; Currency
Method
Returns
Example
.toCurrency(curr?, loc?)
string
numwiz(1999.5).toCurrency("USD") → "$1,999.50"
.toCurrencyIndian(sym?)
string
numwiz(1500000).toCurrencyIndian("₹") → "₹15,00,000.00"
.toCurrencyWords()
string
numwiz(150).toCurrencyWords() → "one hundred fifty dollars"
.toCurrencyWordsIndian()
string
Indian English currency words
.toCurrencyAbbr(sym?)
string
numwiz(1500000).currency("INR").toCurrencyAbbr() → "₹1.5M"
.toCurrencyAbbrIndian(sym?)
string
numwiz(1500000).currency("INR").toCurrencyAbbrIndian() → "₹15 L"
Conversion
Method
Returns
Example
.toBinary()
string
numwiz(10).toBinary() → "1010"
.toOctal()
string
numwiz(8).toOctal() → "10"
.toHex()
string
numwiz(255).toHex() → "ff"
.toBase(b)
string
numwiz(255).toBase(16) → "ff"
Validation (boolean output)
Method
Returns
Example
.isEven()
boolean
numwiz(4).isEven() → true
.isOdd()
boolean
numwiz(3).isOdd() → true
.isPrime()
boolean
numwiz(7).isPrime() → true
.isPositive()
boolean
numwiz(1).isPositive() → true
.isNegative()
boolean
numwiz(-1).isNegative() → true
.isInteger()
boolean
numwiz(3.0).isInteger() → true
.isPalindrome()
boolean
numwiz(121).isPalindrome() → true
.isArmstrong()
boolean
numwiz(153).isArmstrong() → true
.isPerfectNumber()
boolean
numwiz(6).isPerfectNumber() → true
.isPowerOfTwo()
boolean
numwiz(64).isPowerOfTwo() → true
.isFiniteNum()
boolean
numwiz(Infinity).isFiniteNum() → false
Safe ModeIn safe mode, operations that would throw instead set the value to NaN, allowing the chain to continue.
numwiz ( 10 ) . divide ( 0 ) ;
numwiz. safe ( 10 ) . divide ( 0 ) . val ( ) ;
numwiz. safe ( - 9 ) . sqrt ( ) . val ( ) ;
numwiz
. safe ( "hello" as any )
. add ( 1 )
. val ( ) ;
const n = numwiz. safe ( 10 ) . divide ( 0 ) ;
n. isValid ( ) ;
n. val ( ) ;
numwiz ( 100 ) . safe ( ) . divide ( 0 ) . val ( ) ;
new NumWiz ( 100 , { safe: true } ) ;
Static ModulesAll modules are exported by name from the main package:
import { Arithmetic, Formatting, Statistics, Financial, Matrix } from "numwiz" ; Or individually via subpath imports (tree-shakeable — see Subpath Imports ).
Arithmeticimport { Arithmetic } from "numwiz" ;
Method
Signature
Description
Example
add
(...nums: number[])
Sum of all arguments
Arithmetic.add(1,2,3) → 6
subtract
(...nums: number[])
Subtract from first
Arithmetic.subtract(10,3,2) → 5
multiply
(...nums: number[])
Product
Arithmetic.multiply(2,3,4) → 24
divide
(a, b)
Division (throws on b=0)
Arithmetic.divide(10,4) → 2.5
modulus
(a, b)
Remainder
Arithmetic.modulus(10,3) → 1
floorDivide
(a, b)
Integer division
Arithmetic.floorDivide(10,3) → 3
power
(base, exp)
Exponentiation
Arithmetic.power(2,10) → 1024
sqrt
(n)
Square root
Arithmetic.sqrt(16) → 4
cbrt
(n)
Cube root
Arithmetic.cbrt(27) → 3
nthRoot
(n, root)
nth root
Arithmetic.nthRoot(32,5) → 2
abs
(n)
Absolute value
Arithmetic.abs(-7) → 7
negate
(n)
Negation
Arithmetic.negate(5) → -5
reciprocal
(n)
1/n (throws on n=0)
Arithmetic.reciprocal(4) → 0.25
log
(n)
Natural log (n > 0)
Arithmetic.log(Math.E) → 1
log2
(n)
Log base 2
Arithmetic.log2(8) → 3
log10
(n)
Log base 10
Arithmetic.log10(100) → 2
exp
(n)
e^n
Arithmetic.exp(1) → ≈2.718
import { Formatting } from "numwiz" ; Rounding
Method
Signature
Description
Example
toFixed
(num, d?)
Fixed decimal places
Formatting.toFixed(3.14159, 2) → 3.14
toPrecision
(num, digits)
Significant figures
Formatting.toPrecision(3.14159, 4) → 3.142
round
(num)
Standard round
Formatting.round(4.6) → 5
floor
(num)
Floor
Formatting.floor(4.9) → 4
ceil
(num)
Ceiling
Formatting.ceil(4.1) → 5
trunc
(num)
Truncate
Formatting.trunc(-4.9) → -4
bankersRound
(num, d?)
Round half to even
Formatting.bankersRound(0.5) → 0
CommasFormatting. addCommas ( 1234567.89 ) ;
Formatting. addIndianCommas ( 1234567.89 ) ; PercentageFormatting. toPercentage ( 75 ) ;
Formatting. ratioToPercentage ( 0.75 ) ;
Formatting. fromPercentage ( "75%" ) ;
Formatting. fromPercentageRaw ( "75%" ) ; Number to WordsFormatting. toWords ( 1000000 ) ;
Formatting. toWords ( 1000000 , "en" , "indian" ) ;
Formatting. toWords ( 1000000 , "hi" , "indian" ) ;
Formatting. toWordsIndian ( 1500000 , "en" ) ;
Formatting. toWordsWestern ( 1500000 , "en" ) ; PadFormatting. padStart ( 5 , 4 ) ;
Formatting. padStart ( 5 , 4 , "*" ) ;
Formatting. padEnd ( 5 , 4 ) ; OrdinalsFormatting. toOrdinal ( 1 ) ;
Formatting. toOrdinal ( 2 ) ;
Formatting. toOrdinal ( 3 ) ;
Formatting. toOrdinal ( 11 ) ;
Formatting. toOrdinal ( 3 , "hi" ) ; AbbreviationFormatting. abbreviate ( 1234 ) ;
Formatting. abbreviate ( 1500000 ) ;
Formatting. abbreviate ( 2000000000 ) ;
Formatting. abbreviate ( 1500000 , 2 ) ;
Formatting. abbreviateIndian ( 1500000 ) ;
Formatting. abbreviateIndian ( 10000000 ) ;
Formatting. abbreviateIndian ( 1000000000 ) ;
Scale (Western)
Suffix
Value
Thousand
K
10³
Million
M
10⁶
Billion
B
10⁹
Trillion
T
10¹²
Quadrillion
Qa
10¹⁵
Scale (Indian)
Suffix
Value
Thousand
K
10³
Lakh
L
10⁵
Crore
Cr
10⁷
Arab
Arab
10⁹
Kharab
Kh
10¹¹
NotationFormatting. toScientific ( 12345 ) ;
Formatting. toScientific ( 12345 , 2 ) ;
Formatting. toEngineering ( 12345 ) ; OtherFormatting. toRoman ( 2026 ) ;
Formatting. fromRoman ( "MMXXVI" ) ;
Formatting. toFraction ( 0.333 ) ;
Formatting. toFraction ( 0.625 , 16 ) ;
Validationimport { Validation } from "numwiz" ;
Method
Signature
Description
Example
isNumber
(v)
Type guard: finite number
Validation.isNumber("5") → false
isInteger
(v)
Integer check
Validation.isInteger(3.0) → true
isFloat
(v)
Has decimal part
Validation.isFloat(3.5) → true
isFinite
(v)
Not ±Infinity or NaN
Validation.isFinite(Infinity) → false
isNaN
(v)
Is NaN
Validation.isNaN(NaN) → true
isPositive
(v)
> 0
Validation.isPositive(1) → true
isNegative
(v)
< 0
Validation.isNegative(-1) → true
isZero
(v)
=== 0
Validation.isZero(0) → true
isEven
(n)
Even integer
Validation.isEven(4) → true
isOdd
(n)
Odd integer
Validation.isOdd(3) → true
isSafeInteger
(v)
Within Number.MAX_SAFE_INTEGER
isWholeNumber
(v)
Integer ≥ 0
isDivisibleBy
(n, d)
n % d === 0
Validation.isDivisibleBy(10,5) → true
isInRange
(n, min, max)
min ≤ n ≤ max
Validation.isInRange(5,1,10) → true
isPrime
(n)
Prime number
Validation.isPrime(17) → true
isPerfectSquare
(n)
Perfect square
Validation.isPerfectSquare(16) → true
isPerfectCube
(n)
Perfect cube
Validation.isPerfectCube(27) → true
isPowerOfTwo
(n)
Power of 2
Validation.isPowerOfTwo(64) → true
isPowerOfN
(num, n)
Power of n
Validation.isPowerOfN(27,3) → true
isPalindrome
(n)
Digit palindrome
Validation.isPalindrome(121) → true
isArmstrong
(n)
Armstrong number
Validation.isArmstrong(153) → true
isPerfectNumber
(n)
Sum of proper divisors = n
Validation.isPerfectNumber(6) → true
isAbundant
(n)
Sum of proper divisors > n
Validation.isAbundant(12) → true
isDeficient
(n)
Sum of proper divisors < n
Validation.isDeficient(9) → true
isHarshad
(n)
Divisible by digit sum
Validation.isHarshad(18) → true
Comparisonimport { Comparison } from "numwiz" ;
Comparison. isEqual ( 0.1 + 0.2 , 0.3 ) ;
Comparison. isAlmostEqual ( 0.1 + 0.2 , 0.3 ) ;
Comparison. isAlmostEqual ( 0.1 + 0.2 , 0.3 , 1e-15 ) ;
Comparison. isGreaterThan ( 5 , 3 ) ;
Comparison. isLessThan ( 3 , 5 ) ;
Comparison. isGreaterThanOrEqual ( 5 , 5 ) ;
Comparison. isLessThanOrEqual ( 4 , 5 ) ;
Comparison. clamp ( 150 , 0 , 100 ) ;
Comparison. sign ( - 5 ) ;
Comparison. sign ( 0 ) ;
Comparison. sign ( 5 ) ;
Comparison. max ( 1 , 5 , 3 , 9 , 2 ) ;
Comparison. min ( 1 , 5 , 3 , 9 , 2 ) ;
Conversionimport { Conversion } from "numwiz" ; Type conversionConversion. toInteger ( "42.9" ) ;
Conversion. toFloat ( "3.14" ) ;
Conversion. toNumber ( "100" ) ;
Conversion. toString ( 255 ) ; Base conversionConversion. toBinary ( 10 ) ;
Conversion. toOctal ( 8 ) ;
Conversion. toHex ( 255 ) ;
Conversion. toBase ( 255 , 16 ) ;
Conversion. fromBase ( "ff" , 16 ) ; AngleConversion. degreesToRadians ( 180 ) ;
Conversion. radiansToDegrees ( Math. PI ) ; TemperatureConversion. celsiusToFahrenheit ( 0 ) ;
Conversion. fahrenheitToCelsius ( 32 ) ;
Conversion. celsiusToKelvin ( 0 ) ;
Conversion. kelvinToCelsius ( 273.15 ) ;
Conversion. fahrenheitToKelvin ( 32 ) ;
Conversion. kelvinToFahrenheit ( 273.15 ) ; Length & WeightConversion. kmToMiles ( 1 ) ;
Conversion. milesToKm ( 1 ) ;
Conversion. cmToInches ( 2.54 ) ;
Conversion. inchesToCm ( 1 ) ;
Conversion. metersToFeet ( 1 ) ;
Conversion. feetToMeters ( 1 ) ;
Conversion. kgToLbs ( 1 ) ;
Conversion. lbsToKg ( 1 ) ;
Conversion. gramsToOunces ( 28.35 ) ;
Conversion. ouncesToGrams ( 1 ) ; DataConversion. bytesToKB ( 1024 ) ;
Conversion. bytesToMB ( 1048576 ) ;
Conversion. bytesToGB ( 1073741824 ) ; TimeConversion. secondsToMinutes ( 120 ) ;
Conversion. minutesToHours ( 120 ) ;
Conversion. hoursToDays ( 48 ) ;
Conversion. daysToYears ( 365.25 ) ;
Conversion. msToSeconds ( 3000 ) ;
Bitwiseimport { Bitwise } from "numwiz" ; All methods validate that inputs are finite numbers and throw TypeError otherwise.
Method
Signature
Description
Example
and
(a, b)
Bitwise AND
Bitwise.and(5, 3) → 1
or
(a, b)
Bitwise OR
Bitwise.or(5, 3) → 7
xor
(a, b)
Bitwise XOR
Bitwise.xor(5, 3) → 6
not
(a)
Bitwise NOT
Bitwise.not(5) → -6
leftShift
(a, bits)
Left shift <<
Bitwise.leftShift(1, 4) → 16
rightShift
(a, bits)
Signed right shift >>
Bitwise.rightShift(16, 2) → 4
unsignedRightShift
(a, bits)
Unsigned right shift >>>
Bitwise.unsignedRightShift(-1, 0)
getBit
(num, pos)
Get bit at position
Bitwise.getBit(5, 0) → 1
setBit
(num, pos)
Set bit at position
Bitwise.setBit(5, 1) → 7
clearBit
(num, pos)
Clear bit at position
Bitwise.clearBit(7, 1) → 5
toggleBit
(num, pos)
Toggle bit
Bitwise.toggleBit(5, 1) → 7
isBitSet
(num, pos)
Check if bit is set
Bitwise.isBitSet(5, 0) → true
countBits
(num)
Count set bits (popcount)
Bitwise.countBits(7) → 3
isPowerOfTwo
(n)
n > 0 && (n & n-1) === 0
Bitwise.isPowerOfTwo(64) → true
nearestPowerOfTwo
(n)
Closest power of 2
Bitwise.nearestPowerOfTwo(5) → 4
nextPowerOfTwo
(n)
Next higher power of 2
Bitwise.nextPowerOfTwo(5) → 8
xorSwap
(a, b)
Swap via XOR
Bitwise.xorSwap(3, 7) → [7, 3]
toBinaryString
(num, bits?)
Zero-padded binary string
Bitwise.toBinaryString(10, 8) → "00001010"
Trigonometryimport { Trigonometry } from "numwiz" ; All angle arguments are in radians unless explicitly noted.
BasicTrigonometry. sin ( Math. PI / 2 ) ;
Trigonometry. cos ( 0 ) ;
Trigonometry. tan ( Math. PI / 4 ) ; Inverse (throws RangeError for out-of-domain inputs)Trigonometry. asin ( 1 ) ;
Trigonometry. acos ( 1 ) ;
Trigonometry. atan ( 1 ) ;
Trigonometry. atan2 ( 1 , 1 ) ; HyperbolicTrigonometry. sinh ( 0 ) ;
Trigonometry. cosh ( 0 ) ;
Trigonometry. tanh ( 0 ) ;
Trigonometry. asinh ( 0 ) ;
Trigonometry. acosh ( 1 ) ;
Trigonometry. atanh ( 0 ) ; ReciprocalTrigonometry. sec ( 0 ) ;
Trigonometry. csc ( Math. PI / 2 ) ;
Trigonometry. cot ( Math. PI / 4 ) ; Angle ConversionTrigonometry. toRadians ( 180 ) ;
Trigonometry. toDegrees ( Math. PI ) ;
Trigonometry. normalizeDegrees ( 370 ) ;
Trigonometry. normalizeRadians ( 7 ) ; Triangle HelpersTrigonometry. hypot ( 3 , 4 ) ;
Trigonometry. hypot ( 1 , 1 , 1 ) ;
Trigonometry. lawOfCosinesSide ( 3 , 4 , Math. PI / 3 ) ;
Trigonometry. lawOfCosinesAngle ( 3 , 4 , 5 ) ;
Trigonometry. lawOfSinesSide ( 3 , Math. PI / 6 , Math. PI / 4 ) ;
Trigonometry. lawOfSinesAngle ( 3 , 4 , Math. PI / 6 ) ;
Trigonometry. triangleArea ( 3 , 4 , Math. PI / 6 ) ; Trigonometry. log ( Math. E ) ;
Trigonometry. log2 ( 8 ) ;
Trigonometry. log10 ( 100 ) ;
Trigonometry. logN ( 8 , 2 ) ;
Trigonometry. exp ( 1 ) ;
Trigonometry. log1p ( 0 ) ;
Trigonometry. expm1 ( 0 ) ;
Statisticsimport { Statistics } from "numwiz" ;
const data = [ 2 , 4 , 4 , 4 , 5 , 5 , 7 , 9 ] ;
Method
Signature
Description
Example
sum
(arr)
Sum of array
Statistics.sum(data) → 40
mean
(arr)
Arithmetic mean
Statistics.mean(data) → 5
median
(arr)
Middle value
Statistics.median(data) → 4.5
mode
(arr)
Most frequent values
Statistics.mode(data) → [4]
min
(arr)
Minimum
Statistics.min(data) → 2
max
(arr)
Maximum
Statistics.max(data) → 9
range
(arr)
max - min
Statistics.range(data) → 7
variance
(arr)
Population variance
Statistics.variance(data) → 3.5
stdDev
(arr)
Population std dev
Statistics.stdDev(data) → ≈1.87
sampleVariance
(arr)
Sample variance (n-1)
Statistics.sampleVariance(data) → 4
sampleStdDev
(arr)
Sample std dev
Statistics.sampleStdDev(data) → 2
percentile
(arr, p)
p-th percentile
Statistics.percentile(data, 75) → 5.5
quartiles
(arr)
Q1, Q2, Q3 object
Statistics.quartiles(data) → {Q1:4, Q2:4.5, Q3:5.5}
iqr
(arr)
Interquartile range
Statistics.iqr(data) → 1.5
geometricMean
(arr)
Geometric mean
Statistics.geometricMean([1,2,4,8]) → ≈2.83
harmonicMean
(arr)
Harmonic mean
Statistics.harmonicMean([1,2,4]) → ≈1.71
weightedMean
(values, weights)
Weighted average
Statistics.weightedMean([1,2,3],[1,2,1]) → 2
zScore
(value, arr)
Z-score
Statistics.zScore(9, data) → ≈2.14
correlation
(x, y)
Pearson correlation
Statistics.correlation([1,2,3],[2,4,6]) → 1
frequency
(arr)
Value counts map
Statistics.frequency([1,1,2,3]) → {1:2, 2:1, 3:1}
skewness
(arr)
Distribution skewness
Statistics.skewness(data) → ≈0.95
Financialimport { Financial } from "numwiz" ;
Method
Signature
Description
Example
simpleInterest
(principal, rate, time)
SI = P×R×T/100
Financial.simpleInterest(10000, 5, 3) → 1500
compoundInterest
(principal, rate, time, n?)
CI (default n=1/year)
Financial.compoundInterest(10000, 5, 3) → ≈1576
emi
(principal, annualRate, months)
Monthly loan EMI
Financial.emi(500000, 10, 120) → ≈6607
futureValue
(pv, rate, periods)
FV of investment
Financial.futureValue(10000, 8, 5) → ≈14693
presentValue
(fv, rate, periods)
PV of future sum
Financial.presentValue(14693, 8, 5) → ≈10000
roi
(gain, cost)
Return on investment %
Financial.roi(15000, 10000) → 50
cagr
(start, end, years)
Compound annual growth %
Financial.cagr(10000, 20000, 5) → ≈14.87
grossProfit
(revenue, cogs)
Revenue - COGS
Financial.grossProfit(50000, 30000) → 20000
grossMargin
(revenue, cogs)
Gross profit %
Financial.grossMargin(50000, 30000) → 40
netProfit
(revenue, expenses)
Revenue - Expenses
Financial.netProfit(50000, 40000) → 10000
markup
(cost, sellingPrice)
Markup % on cost
Financial.markup(30000, 50000) → ≈66.67
discount
(original, discountPct)
Price after discount
Financial.discount(1000, 20) → 800
taxAmount
(amount, taxRate)
Tax portion
Financial.taxAmount(1000, 18) → 180
priceWithTax
(amount, taxRate)
Amount inclusive of tax
Financial.priceWithTax(1000, 18) → 1180
sipFutureValue
(monthly, annualRate, years)
SIP maturity amount
Financial.sipFutureValue(5000, 12, 10) → ≈1163390
amortizationSchedule
(principal, annualRate, months)
Full amortization table
Returns AmortizationEntry[]
amortizationSchedule exampleconst schedule = Financial. amortizationSchedule ( 500000 , 10 , 12 ) ;
schedule[ 0 ] ;
Advancedimport { Advanced } from "numwiz" ; CombinatoricsAdvanced. factorial ( 5 ) ;
Advanced. permutation ( 5 , 2 ) ;
Advanced. combination ( 5 , 2 ) ;
Advanced. catalan ( 5 ) ;
Advanced. pascal ( 4 ) ; Number TheoryAdvanced. gcd ( 12 , 8 ) ;
Advanced. lcm ( 4 , 6 ) ;
Advanced. gcdArray ( [ 12 , 8 , 6 ] ) ;
Advanced. lcmArray ( [ 4 , 6 , 10 ] ) ;
Advanced. primeFactors ( 60 ) ;
Advanced. divisors ( 12 ) ;
Advanced. sumOfDivisors ( 12 ) ;
Advanced. nextPrime ( 10 ) ;
Advanced. primesInRange ( 10 , 30 ) ;
Advanced. eulerTotient ( 12 ) ; SequencesAdvanced. fibonacci ( 10 ) ;
Advanced. fibonacciSequence ( 8 ) ;
Advanced. collatz ( 6 ) ; Digit OperationsAdvanced. digitSum ( 12345 ) ;
Advanced. digitalRoot ( 9875 ) ;
Advanced. countDigits ( 12345 ) ;
Advanced. reverseNumber ( 12345 ) ;
Advanced. isPalindrome ( 121 ) ; Math UtilitiesAdvanced. lerp ( 0 , 100 , 0.5 ) ;
Advanced. inverseLerp ( 0 , 100 , 50 ) ;
Advanced. map ( 5 , 0 , 10 , 0 , 100 ) ;
Advanced. percentageOf ( 15 , 200 ) ;
Advanced. whatPercent ( 30 , 200 ) ;
Advanced. percentChange ( 80 , 100 ) ;
Sequencesimport { Sequences } from "numwiz" ;
Method
Signature
Description
Example
fibonacci
(count)
Fibonacci sequence
Sequences.fibonacci(6) → [0,1,1,2,3,5]
lucas
(count)
Lucas numbers
Sequences.lucas(5) → [2,1,3,4,7]
primes
(count)
First N primes
Sequences.primes(5) → [2,3,5,7,11]
triangular
(count)
Triangular numbers
Sequences.triangular(5) → [1,3,6,10,15]
square
(count)
Square numbers
Sequences.square(5) → [1,4,9,16,25]
cube
(count)
Cube numbers
Sequences.cube(5) → [1,8,27,64,125]
arithmetic
(start, diff, count)
Arithmetic progression
Sequences.arithmetic(1, 2, 5) → [1,3,5,7,9]
geometric
(start, ratio, count)
Geometric progression
Sequences.geometric(1, 2, 5) → [1,2,4,8,16]
custom
(count, fn)
Custom sequence via index fn
Sequences.custom(4, i => i*i) → [0,1,4,9]
Sequences. custom ( 5 , ( i) => 2 ** i) ;
Sequences. custom ( 5 , ( i) => i * 3 + 1 ) ;
Randomimport { Random } from "numwiz" ;
Method
Signature
Description
Example
float
()
Random float [0, 1)
Random.float()
floatBetween
(min, max)
Random float in [min, max)
Random.floatBetween(1, 5)
intBetween
(min, max)
Random integer (inclusive)
Random.intBetween(1, 10)
boolean
()
Random true/false
Random.boolean()
coin
()
"heads" or "tails"
Random.coin()
dice
(sides?)
Roll a die (default 6)
Random.dice(20) → 1–20
pick
<T>(arr)
Random element
Random.pick([10, 20, 30])
shuffle
<T>(arr)
Shuffled copy (new array)
Random.shuffle([1,2,3,4,5])
sample
<T>(arr, count)
Random subset
Random.sample([1,2,3,4,5], 3)
generateList
(count, min?, max?)
N random integers (repeats allowed)
Random.generateList(5, 1, 10)
uniqueList
(count, min?, max?)
N unique random integers
Random.uniqueList(5, 1, 20)
gaussian
(mean?, stdDev?)
Normal distribution sample
Random.gaussian(0, 1)
weighted
<T>(items)
Weighted random pick
See example below
uuid
()
UUID v4 string
Random.uuid() → "xxxxxxxx-..."
Random. weighted ( [
{ value: "common" , weight: 70 } ,
{ value: "rare" , weight: 25 } ,
{ value: "epic" , weight: 5 } ,
] ) ;
Rangeimport { Range } from "numwiz" ;
Method
Signature
Description
Example
create
(start, end, step?)
Generate number array
Range.create(1, 5) → [1,2,3,4,5]
includes
(num, min, max)
Check membership [min, max]
Range.includes(5, 1, 10) → true
wrap
(num, min, max)
Wrap around range
Range.wrap(370, 0, 360) → 10
bounce
(num, min, max)
Bounce / ping-pong
Range.bounce(7, 0, 5) → 3
chunk
(start, end, size)
Split range into chunks
Range.chunk(1, 9, 3) → [[1,2,3],[4,5,6],[7,8,9]]
Range. create ( 0 , 10 , 2 ) ;
Range. create ( 10 , 1 , - 3 ) ;
Range. wrap ( 370 , 0 , 360 ) ;
Range. bounce ( 7 , 0 , 5 ) ;
Range. chunk ( 1 , 9 , 3 ) ;
Currencyimport { Currency } from "numwiz" ;
Method
Signature
Description
Example
format
(amount, currency?, locale?)
Intl.NumberFormat formatting
Currency.format(1234567, "USD") → "$1,234,567.00"
formatIndian
(amount, symbol?)
Indian comma grouping
Currency.formatIndian(1234567, "₹") → "₹12,34,567.00"
getSymbol
(code)
Currency symbol lookup
Currency.getSymbol("INR") → "₹"
convert
(amount, fromRate, toRate)
Currency rate conversion
Currency.convert(100, 1, 83) → 8300
abbreviateWestern
(amount, symbol?, decimals?)
Western abbreviation
Currency.abbreviateWestern(1500000, "$") → "$1.5M"
abbreviateIndian
(amount, symbol?, decimals?)
Indian abbreviation
Currency.abbreviateIndian(1500000, "₹") → "₹15.0 L"
toWords
(amount, currency?, locale?)
Western scale words
Currency.toWords(150, "USD") → "one hundred fifty dollars"
toWordsIndian
(amount, currency?, locale?)
Indian-scale words
Currency.toWordsIndian(150, "INR", "hi") → "एक सौ पचास रुपये"
toWordsHindi
(amount, currency?)
Hindi convenience method
Currency.toWordsHindi(1500) → "पंद्रह सौ रुपये"
Supported currency symbols: USD ($), EUR (€), GBP (£), INR (₹), JPY/CNY (¥), AUD (A$), CAD (C$), BDT (৳), PKR (₨), BRL (R$), RUB (₽), KRW (₩), TRY (₺), THB (฿), PHP (₱), VND (₫), NGN (₦), and more.
NumberWordsDirect access to the multi-locale word conversion engine.
import { NumberWords } from "numwiz" ;
NumberWords. toWords ( 42 ) ;
NumberWords. toWords ( 42 , "hi" ) ;
NumberWords. toWords ( 42 , "de" ) ;
NumberWords. toWords ( 42 , "es" ) ;
NumberWords. toWords ( 42 , "fr" ) ;
NumberWords. toWords ( 1000000 , "en" , "indian" ) ;
NumberWords. toWords ( 1000000 , "en" , "western" ) ;
NumberWords. toWordsIndian ( 1500000 , "en" ) ;
NumberWords. toWordsWestern ( 1500000 , "en" ) ;
NumberWords. currencyToWords ( 150 , "USD" , "en" , "western" ) ;
MatrixFull-featured matrix library with both a static functional API (plain arrays in, plain arrays out) and a chainable instance API (fluent builder pattern).
import { Matrix } from "numwiz" ;
import Matrix from "numwiz/matrix" ; Creation
Method
Signature
Description
Example
create
(rows, cols, fill?)
Matrix filled with value
Matrix.create(2,3) → [[0,0,0],[0,0,0]]
identity
(n)
n×n identity
Matrix.identity(3)
zeros
(rows, cols)
All zeros
Matrix.zeros(2,2)
ones
(rows, cols)
All ones
Matrix.ones(2,2)
fill
(rows, cols, v)
Filled with v
Matrix.fill(2,2,7)
diagonal
(values)
Diagonal matrix
Matrix.diagonal([1,2,3])
random
(rows, cols, min?, max?, integers?)
Random matrix
Matrix.random(3,3,0,10,true)
fromFlat
(flat, rows, cols)
Reshape 1D to 2D
Matrix.fromFlat([1,2,3,4],2,2)
columnVector
(values)
n×1 matrix
Matrix.columnVector([1,2,3])
rowVector
(values)
1×n matrix
Matrix.rowVector([1,2,3])
rotation2D
(angle)
2×2 rotation
Matrix.rotation2D(Math.PI/2)
scaling
(...factors)
Diagonal scale matrix
Matrix.scaling(2,3)
hilbert
(n)
Hilbert matrix
Matrix.hilbert(3)
vandermonde
(values, cols)
Vandermonde matrix
Matrix.vandermonde([1,2,3],4)
Inspectionconst m = [
[ 1 , 2 , 3 ] ,
[ 4 , 5 , 6 ] ,
] ;
Matrix. shape ( m) ;
Matrix. rows ( m) ;
Matrix. cols ( m) ;
Matrix. size ( m) ;
Matrix. get ( m, 0 , 1 ) ;
Matrix. set ( m, 0 , 0 , 9 ) ;
Matrix. getRow ( m, 1 ) ;
Matrix. getCol ( m, 0 ) ;
Matrix. getDiagonal ( m) ;
Matrix. flatten ( m) ;
Matrix. clone ( m) ; Arithmeticconst A = [
[ 1 , 2 ] ,
[ 3 , 4 ] ,
] ,
B = [
[ 5 , 6 ] ,
[ 7 , 8 ] ,
] ;
Matrix. add ( A , B ) ;
Matrix. subtract ( A , B ) ;
Matrix. multiply ( A , B ) ;
Matrix. scale ( A , 3 ) ;
Matrix. negate ( A ) ;
Matrix. hadamard ( A , B ) ;
Matrix. elementDivide ( A , B ) ;
Matrix. elementPower ( A , 2 ) ;
Matrix. power ( A , 3 ) ;
Matrix. scalarAdd ( A , 10 ) ;
Matrix. scalarSubtract ( A , 1 ) ; Matrix. transpose ( [
[ 1 , 2 , 3 ] ,
[ 4 , 5 , 6 ] ,
] ) ;
Matrix. inverse ( [
[ 4 , 7 ] ,
[ 2 , 6 ] ,
] ) ;
Matrix. adjugate ( A ) ;
Matrix. cofactor ( A , 0 , 0 ) ;
Matrix. cofactorMatrix ( A ) ;
Matrix. minor ( A , 0 , 0 ) ; Row / Column OperationsMatrix. swapRows ( A , 0 , 1 ) ;
Matrix. swapCols ( A , 0 , 1 ) ;
Matrix. scaleRow ( A , 0 , 2 ) ;
Matrix. addRowMultiple ( A , 1 , 0 , - 2 ) ;
Matrix. ref ( A ) ;
Matrix. rref ( A ) ; Scalar PropertiesMatrix. determinant ( [
[ 1 , 2 ] ,
[ 3 , 4 ] ,
] ) ;
Matrix. trace ( [
[ 1 , 2 ] ,
[ 3 , 4 ] ,
] ) ;
Matrix. rank ( [
[ 1 , 2 ] ,
[ 2 , 4 ] ,
] ) ;
Matrix. sum ( A ) ;
Matrix. min ( A ) ;
Matrix. max ( A ) ;
Matrix. mean ( A ) ;
Matrix. normFrobenius ( A ) ;
Matrix. normInf ( A ) ;
Matrix. norm1 ( A ) ;
Matrix. sumAxis ( A , "row" ) ;
Matrix. sumAxis ( A , "col" ) ; Decomposition & Solvingconst { L , U , P } = Matrix. lu ( A ) ;
const { Q , R } = Matrix. qr ( A ) ;
Matrix. eigenvalues ( [
[ 2 , 1 ] ,
[ 1 , 2 ] ,
] ) ;
Matrix. eigenvalues2x2 ( [
[ 0 , - 1 ] ,
[ 1 , 0 ] ,
] ) ;
Matrix. solve (
[
[ 2 , 1 ] ,
[ 1 , 3 ] ,
] ,
[ 5 , 10 ]
) ;
Matrix. solveCramer (
[
[ 2 , 1 ] ,
[ 1 , 3 ] ,
] ,
[ 5 , 10 ]
) ; Boolean ChecksMatrix. isSquare ( A ) ;
Matrix. isIdentity ( Matrix. identity ( 3 ) ) ;
Matrix. isSymmetric ( [
[ 1 , 2 ] ,
[ 2 , 1 ] ,
] ) ;
Matrix. isDiagonal ( Matrix. diagonal ( [ 1 , 2 ] ) ) ;
Matrix. isUpperTriangular ( [
[ 1 , 2 ] ,
[ 0 , 3 ] ,
] ) ;
Matrix. isLowerTriangular ( [
[ 1 , 0 ] ,
[ 2 , 3 ] ,
] ) ;
Matrix. isOrthogonal ( Matrix. identity ( 2 ) ) ;
Matrix. isSingular ( [
[ 1 , 2 ] ,
[ 2 , 4 ] ,
] ) ;
Matrix. isZero ( Matrix. zeros ( 2 , 2 ) ) ;
Matrix. isVector ( [ [ 1 , 2 , 3 ] ] ) ;
Matrix. isRowVector ( [ [ 1 , 2 , 3 ] ] ) ;
Matrix. isColumnVector ( [ [ 1 ] , [ 2 ] , [ 3 ] ] ) ;
Matrix. isSameShape ( A , B ) ;
Matrix. equals ( A , A ) ;
Matrix. isEqual ( A , A , 1e-10 ) ; Vector OperationsMatrix. dot ( [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] ) ;
Matrix. cross ( [ 1 , 0 , 0 ] , [ 0 , 1 , 0 ] ) ;
Matrix. magnitude ( [ 3 , 4 ] ) ;
Matrix. normalize ( [ 3 , 4 ] ) ;
Matrix. angleBetween ( [ 1 , 0 ] , [ 0 , 1 ] ) ; AggregationMatrix. rowSums ( m) ;
Matrix. colSums ( m) ;
Matrix. rowMeans ( m) ;
Matrix. colMeans ( m) ; Functional / Element-wiseMatrix. map ( m, ( v, i, j) => v * 2 ) ;
Matrix. forEach ( m, ( v, i, j) => { } ) ;
Matrix. every ( m, ( v) => v > 0 ) ;
Matrix. some ( m, ( v) => v > 5 ) ;
Matrix. round ( m, 2 ) ;
Matrix. abs ( m) ; StructureMatrix. hStack ( A , B ) ;
Matrix. vStack ( A , B ) ;
Matrix. hConcat ( A , B ) ;
Matrix. vConcat ( A , B ) ;
Matrix. slice ( m, 0 , 0 , 2 , 2 ) ;
Matrix. subMatrix ( m, 0 , 0 , 2 , 2 ) ;
Matrix. reshape ( [ [ 1 , 2 , 3 , 4 , 5 , 6 ] ] , 2 , 3 ) ; DisplayMatrix. toString ( A ) ;
Matrix. print ( A ) ;
Matrix. toHTML ( A ) ;
Matrix. toJSON ( A ) ;
Matrix. fromJSON ( json) ; Chainable Instance APIconst result = new Matrix ( [
[ 1 , 2 ] ,
[ 3 , 4 ] ,
] )
. add ( [
[ 10 , 20 ] ,
[ 30 , 40 ] ,
] )
. multiply ( [
[ 1 , 0 ] ,
[ 0 , 1 ] ,
] )
. scale ( 2 )
. transpose ( )
. round ( 4 )
. toArray ( ) ;
new Matrix ( [
[ 1 , 2 ] ,
[ 3 , 4 ] ,
] ) . determinant ( ) ;
new Matrix ( [
[ 1 , 2 ] ,
[ 3 , 4 ] ,
] ) . trace ( ) ;
new Matrix ( [
[ 1 , 0 ] ,
[ 0 , 1 ] ,
] ) . isIdentity ( ) ;
const { L , U , P } = new Matrix ( A ) . lu ( ) ;
const { Q , R } = new Matrix ( A ) . qr ( ) ;
new Matrix ( [
[ 2 , 1 ] ,
[ 1 , 3 ] ,
] )
. solve ( [ [ 5 ] , [ 10 ] ] )
. toArray ( ) ; Chainable methods: add, subtract, multiply, scale, negate, hadamard, elementDivide, elementPower, power, scalarAdd, scalarSubtract, transpose, inverse, adjugate, ref, rref, solve, hStack, vStack, slice, reshape, swapRows, swapCols, map, round, abs, clone, print
Terminal methods: toArray, flatten, getDiagonal, getRows, getCols, getShape, getSize, getElement, determinant, trace, sum, min, max, mean, rank, norm, normFrobenius, eigenvalues, isSquare, isIdentity, isSymmetric, isDiagonal, isUpperTriangular, isLowerTriangular, isOrthogonal, isSingular, isZero, equals, isEqual, toString, lu, qr
Subpath ImportsEach module is independently importable for tree-shaking:
import Arithmetic from "numwiz/arithmetic" ;
import Comparison from "numwiz/comparison" ;
import Validation from "numwiz/validation" ;
import Conversion from "numwiz/conversion" ;
import Bitwise from "numwiz/bitwise" ;
import Trigonometry from "numwiz/trigonometry" ;
import Range from "numwiz/range" ;
import Statistics from "numwiz/statistics" ;
import Financial from "numwiz/financial" ;
import Sequences from "numwiz/sequences" ;
import Random from "numwiz/random" ;
import Advanced from "numwiz/advanced" ;
import Formatting from "numwiz/formatting" ;
import Currency from "numwiz/currency" ;
import Matrix from "numwiz/matrix" ;
import NumberWords from "numwiz/number-words" ;
import type { Matrix2D, LUResult, QRResult } from "numwiz/types" ;
Supported Locales
Code
Language
Preferred scale
en
English
Western & Indian
hi
Hindi
Indian
de
German
Western
es
Spanish
Western
fr
French
Western
ar
Arabic
Western
bn
Bengali
Indian
mr
Marathi
Indian
gu
Gujarati
Indian
ta
Tamil
Indian
Examplesimport { Formatting } from "numwiz" ;
Formatting. toWords ( 42 , "en" ) ;
Formatting. toWords ( 42 , "hi" ) ;
Formatting. toWords ( 42 , "de" ) ;
Formatting. toWords ( 42 , "es" ) ;
Formatting. toWords ( 42 , "fr" ) ;
Formatting. toWords ( 42 , "ar" ) ;
Formatting. toWords ( 42 , "bn" ) ;
Formatting. toWords ( 42 , "mr" ) ;
Formatting. toWords ( 42 , "gu" ) ;
Formatting. toWords ( 42 , "ta" ) ;
Formatting. toOrdinal ( 1 , "en" ) ;
Formatting. toOrdinal ( 3 , "hi" ) ;
Formatting. toWords ( 10000000 , "en" , "indian" ) ;
Formatting. toWords ( 10000000 , "hi" , "indian" ) ;
TypeScript SupportNumWiz is written in TypeScript 5.x — types are bundled, no separate @types/numwiz needed.
import numwiz, {
NumWiz,
Arithmetic,
Matrix,
Statistics,
Financial,
type NumWizOptions ,
} from "numwiz" ;
import type {
Matrix2D,
LUResult,
QRResult,
AmortizationEntry,
} from "numwiz/types" ;
const m: Matrix2D = [
[ 1 , 2 ] ,
[ 3 , 4 ] ,
] ;
const { L , U , P } : LUResult = Matrix. lu ( m) ;
const schedule: AmortizationEntry[ ] = Financial. amortizationSchedule (
500000 ,
10 ,
12
) ; Key exported types:
Type
Description
Matrix2D
number[][]
LUResult
{ L: Matrix2D, U: Matrix2D, P: Matrix2D }
QRResult
{ Q: Matrix2D, R: Matrix2D }
EigenvalueResult
number | { real: number; imag: number }
AmortizationEntry
{ month, emi, principal, interest, balance }
NumWizOptions
{ safe?: boolean }
WeightedItem<T>
{ value: T, weight: number }
LocaleData
Locale definition structure
Error Reference
Situation
Error type
Examples
Invalid number input
TypeError
Non-number, NaN passed to strict method
Wrong matrix dimensions
RangeError
Non-square for inverse, size mismatch for multiply
Out-of-range index
RangeError
Matrix.get(m, 99, 0)
Division by zero (scalar)
Error
Arithmetic.divide(10, 0)
Division by zero (matrix)
Error
Matrix.elementDivide(A, zeroMatrix)
Singular matrix
Error
Matrix.inverse(singularMatrix)
Negative sqrt / log of non-positive
RangeError
Arithmetic.sqrt(-1) in non-safe mode
Inverse trig out-of-domain
RangeError
Trigonometry.asin(2)
Locale not registered
Error
Unknown locale code
Linearly dependent columns (QR)
Error
Matrix.qr on rank-deficient matrix
Use numwiz.safe() on the chainable API to convert runtime errors into NaN values instead of throws.
LicenseMIT © 2026 Subroto Saha