float-format

1.1.1 • Public • Published

float format

format and compare float number in javascript

API

compare(float1, float2, precision)

if precision is undefined, then use the minimum precision of float1 and float2, else use given precision to compare two numbers

example

const ff = require("float-format");
ff(0.2 * 0.2); // 0.04
0.2 * 0.2; // 0.04000000000000001
 
0.2 * 0.2 == 0.04; // false
ff(0.2 * 0.2) == 0.04; // true
0.2 * 0.2 - 0.04; // 6.938893903907228e-18
 
ff.compare(3.546, 3.54); // false, 3.55 != 3.54
ff.compare(4.222, 4, 0); // true, 4 == 4
ff.compare(4.222, 4, 2); // false 4.22 != 4

Readme

Keywords

Package Sidebar

Install

npm i float-format

Weekly Downloads

57

Version

1.1.1

License

MIT

Unpacked Size

4 kB

Total Files

5

Last publish

Collaborators

  • truth1984