@t0ri/math
v5.2.1
Published
   
method rounds the Number it is called on to the nearest whole number.
let num = 9.99
num.round() -> 10
Ceil
The .ceil()
method rounds the Number it is called on to the higher whole number.
let num = 9.99
num.ceil() -> 10
Floor
The .floor()
method rounds the Number it is called on to the lower whole number.
let num = 9.99
num.floor() -> 9
Pad
The .pad(x, y)
method pads the Number it is called on with 0s in order to reach a total of digits (x, y) on each side of the decimal point.
Returns a String.
let num = 9.99
34.801.pad(4,3) -> 0009.990
Degrees to Radians
The .degToRad()
method returns a number's radian value.
Accepts an optional argument to return a fixed amount of decimal numbers.
let num = 1
num.degToRad() -> 0.017453292519943295
num.degToRad(6) -> 0.017453
Radians to Degrees
The .radToDeg()
method returns a number's degree value.
Accepts an optional argument to return a fixed amount of decimal numbers.
let num = 1
num.radToDeg() ->
num.radToDeg(4) -> 57.2958
Dollar Amount
The .toDollars()
method returns a numeric value formatted in USD.
let num = 1
num.toDollars() -> '$1.00'
Tax
The .tax(rate)
method returns an amount with tax applied.
Accepts optional argument (number) to calculate tax on amount.
Without argument, tax rate defaults to .25
.
let num = 1
num.tax(0.25) -> 1.25
Interest
The .interest(months, rate)
method calculates interest over time.
let num = 1
num.interest(2, 16) -> 1.35
Mortgage
The .mortgage(years, rate)
method returns the monthly mortgage payment of the number it is called on.
Rate is interest rate, years is the amount of months to pay.
let num = 1
num.mortgage(10, .02) -> 1
Number to Hex
The .toHex()
method returns a string containing the hexadecimal value of the number it is caled on.
This method accepts an optional boolean argument to control the return of an octothorpe
.
let num = 12
num.toHex() -> 'c'
num.toHex(true) -> '#c'