# @cenz/math-lib

The utlimate extension of the Number object built into javascript

## Usage no npm install needed!

``````<script type="module">
import cenzMathLib from 'https://cdn.skypack.dev/@cenz/math-lib';
</script>``````

# math-lib

## Description

An extension of the Number prototype chain to add some more functions to the Number object. More information about what this extension adds can be found in the API section.

## API

### round

Round a number to it's nearest whole number

Returns Number the closest whole number to the original number

### floor

Round a number down to it's nearest whole number.

Returns Number the closest whole number to the rounded down original number.

### ceil

Round a number up to it's closest whole number

#### Examples

``````Number(5.32).ceil() -> 6
``````

Returns Number the closest whole number to the rounded up original number.

Pad a number with a specified amount of zeros (On either the left or right side)

#### Parameters

• `leftPadding`
• `rightPadding`

#### Examples

``````Number(5.3234).pad(4,5) -> 0004.32340
``````

Returns String A padded string that indicates.

Convert a number from degrees to radians

#### Examples

``````Number(20).degToRad() -> 0.349066
``````

Returns Number The converted number in radians

Convert a number from radians to degrees

#### Examples

``````Number(1).radToDeg() -> 57.2958
``````

Returns Number the converted number in degrees.

### toDollars

Convert a number to USD.

#### Examples

``````Number(1).toDollars() -> \$1.00
Number(1.05).toDollars() -> \$1.05
Number(0.5).toDollars() -> ยข0.5
``````

Returns String The dollar representation of the number

### tax

Return the tax amount from the number that would be applied given the rate

#### Parameters

• `rate` Number The tax rate to be applied where the rate is 0 <= rate <= 100 or the rate is 0 <= 100

#### Examples

``````Number(10).tax(10) -> 1.00
Number(60).tax(25) -> 15.00
``````

Returns Number the total tax amount of the current number multiplied by the rate

### withTax

Return this number with a specified tax rate applied to it.

#### Parameters

• `rate` Number The tax rate to be applied

#### Examples

``````Number(10).withTax(10) -> 11
Number(200).withTax(50) -> 300
``````

Returns Number a new number that has the tax of the original number applied.

### interest

Calculate the interest on a number given the interest rate, years, and optional decimal places to round to

#### Parameters

• `rate` Number The interest rate
• `years` Number The amount of years the rate is applied to return {String} a string containing the total interest paid on a given number
• `decimalPlaces` (optional, default `2`)

### mortage

Calculate the monthly payments for a mortage given a principal (Number)

#### Parameters

• `interestRate` Number The yearly rate of interest
• `numberOfYears` Number the years remaining for the mortage

Returns Number The monthly mortage payments that need to be made to pay off the mortage

### decimalToHex

convert a decimal number to hexadecimal, all thanks to the help of this stack overflow question: https://stackoverflow.com/questions/57803/how-to-convert-decimal-to-hexadecimal-in-javascript

Returns String The string containing the number converted to hexadecimal

### GOLDENRATIO

The golden ratio as approximated by: https://en.wikipedia.org/wiki/Golden_ratio

Type: Number