floatp
v1.0.7
Published
Return correct number from a floating point number.
Downloads
26
Readme
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()