float

Provides methods for comparing and rounding floating point numbers

Float

Travis build status:

GitHub repository: github.com/mex/float

NPM package: npmjs.org/package/float

Install through NPM: npm install float

Install through Bower: bower install float

var f = require('float');
 
var a = 2.15;
var b = 3.46;
var c = 5.61;
var ab = f.round(a + b);
if (f.equals(ab, c) {
  console.log('They are equal!');
} else {
  console.log('Someone clearly failed at some point...');
}
  • round(number, precision)
    • Rounds the number to the given number of decimals.
    • Parameters:
      • number (float)
      • precision (integer): Number of decimals
    • Return:
      • float
  • floor(number, precision)
    • Floors the number to the given number of decimals.
    • Parameters:
      • number (float)
      • precision (integer): Number of decimals
    • Return:
      • float
  • ceil(number, precision)
    • Ceils the number to the given number of decimals.
    • Parameters:
      • number (float)
      • precision (integer): Number of decimals
    • Return:
      • float
  • equals(a, b[, d])
    • Compares the arguments and return whether they are equal.
    • Parameters:
      • a (float)
      • b (float)
      • d (integer): Number of decimals
    • Return:
      • boolean
  • lessThan(a, b[, d])
    • Compares the arguments and return whether a is less than b.
    • Parameters:
      • a (float)
      • b (float)
      • d (integer): Number of decimals
    • Return:
      • boolean
  • lessThanOrEquals(a, b[, d])
    • Compares the arguments and return whether a is less than or equal to b.
    • Parameters:
      • a (float)
      • b (float)
      • d (integer): Number of decimals
    • Return:
      • boolean
  • greaterThan(a, b[, d])
    • Compares the arguments and return whether a is greater than b.
    • Parameters:
      • a (float)
      • b (float)
      • d (integer): Number of decimals
    • Return:
      • boolean
  • greaterThanOrEquals(a, b[, d])
    • Compares the arguments and return whether a is greater than or equal to b.
    • Parameters:
      • a (float)
      • b (float)
      • d (integer): Number of decimals
    • Return:
      • boolean