floatp

1.0.7 • Public • Published

About

Return correct number from a floating point number.

let fp = require('floatp')
v = 0.1 + 0.2 // v: 0.30000000000000004
v = fp(0.1 + 0.2) // v: 0.3

eg2: Array

v = 0.1 + 0.2
ar = [v, v]
ar = fp(ar) // ar: [0.3, 0.3]

eg3: Object (recursive)

v = 0.1 + 0.2
ar = [v, v]
ob = {a:v, b:ar}
ob = fp(ob) // ob: { a: 0.3, b: [ 0.3, 0.3 ] }

eg4: (extra) change precision (default is 12 precision)

v = 3191.379480000001
v = fp(v, 10) // v: 3191.37948

require globally

require('floatp').gb()
floatP()
floatp()
fp() // access globally // global.fp()

Package Sidebar

Install

npm i floatp

Weekly Downloads

22

Version

1.0.7

License

ISC

Unpacked Size

1.86 kB

Total Files

4

Last publish

Collaborators

  • jydev