A math library containing properties and methods extended onto Number.prototype
.
Number.goldenRatio
is equal to 1.61803398875
.
let num = Number.goldenRatio
num -> 1.61803398875
The .round()
method rounds the Number it is called on to the nearest whole number.
let num = 9.99
num.round() -> 10
The .ceil()
method rounds the Number it is called on to the higher whole number.
let num = 9.99
num.ceil() -> 10
The .floor()
method rounds the Number it is called on to the lower whole number.
let num = 9.99
num.floor() -> 9
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
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
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
The .toDollars()
method returns a numeric value formatted in USD.
let num = 1
num.toDollars() -> '$1.00'
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
The .interest(months, rate)
method calculates interest over time.
let num = 1
num.interest(2, 16) -> 1.35
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
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'