View on GitHub

bigarith.js

Do very large math to precision!

floor()

floor() returns the largest integer less than or equal to a given number. There is a method function and a static method function.

Syntax

method function
ba.floor();
static method function
BigArith.floor(n);

Parameters

method function

none

static method function

n - Required - {string|number|BigArith}

The number to floor. This could be a string of digits, a number, or a BigArith object.

Return value

method function - {BigArith}

A BigArith object with its value equals to the floored value of the BigArith object it is called on.

static method function - {BigArith}

A BigArith object with its value equals to the floored value of n.

Description

There are two functions which could be used, the method function, and the static method function. The method function takes no parameter and returns a BigArith whose value equals the largest integer less than or equal to that of the BigArith object it is called on.

The static method function takes one parameter (n) and is always used as BigArith.floor(). It returns the largest integer less than or equal to n.

Any number parameter (that is not strings of digits or a BigArith) should be between the Number.MIN_SAFE_INTEGER and Number.MAX_SAFE_INTEGER limits.

Examples

In the server-side, always remember to add the line var BigArith = require('bigarith.js'); however every other thing remains the same in both server-side and client-side code.

Using method function

var ba = new BigArith("-17031986.001");
ba = ba.floor(); //BigArith object with value "-17031987"

ba = new BigArith("+17031986.001");
ba = ba.floor(); //BigArith object with value "17031986"

ba = new BigArith("999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999.999");
ba = ba.floor(); //BigArith object with value "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"

ba = new BigArith();
ba = ba.floor(); //BigArith object with value "0" 

ba = new BigArith(null);
ba = ba.floor(); //BigArith object with value "0" 

ba = new BigArith(NaN);
ba = ba.floor(); //NaN

Using the static method function

var ba = BigArith.floor("-17031986.001"); //BigArith object with value "-17031987"
ba = BigArith.floor("+17031986.001"); //BigArith object with value "17031986"
ba = BigArith.floor("999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999.999"); //BigArith object with value "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
ba = BigArith.floor(); //BigArith object with value "0"
ba = BigArith.floor(null); //BigArith object with value "0"
ba = BigArith.floor(NaN); //NaN

More examples here. Full documentation here

See also