y2fixed
v1.0.3
Published
Similar to .toFixed(), but can be ceil, floor or round (default)
Downloads
35
Maintainers
Readme
About
Similar to .toFixed(), but can be ceil, floor or round (default)
const y2fixed = require('y2fixed')
let v = 1.234
t = y2fixed(v, 2, "floor") // t: 1.23
t = y2fixed(v, 2, "ceil") // t: 1.24
t = y2fixed(v, 2) // t: 1.23 (round)
parameters
y2fixed(v, decimals, op)
- v: number|string
- decimals: 0-100 integer
- op (options): string or object
- string: ceil|floor|undefined(round)
- object: {type, string}
- type: ceil|floor|undefined(round)
- string|str|s: 0|1, return as string, default: 0 (return as number)
- ceil: 0|1 // default 0; shorthand for type:'ceil'
- floor: 0|1 // default 0; shorthand for type:'floor'
- return: number(default)|string(op:{str:1})
eg2 (options)
let v = 1.2345
t = y2fixed(v, 2, {type:'floor', s:1}) // string|str|st|s: 0|1, return as string, default 0: number
t = y2fixed(v, 2, "ceil") // t: 1.24
t = y2fixed(v, 2) // t: 1.23, same as v.toFixed(2)
t = y2fixed(v, 3, {floor:1}) // t:1.234
notes
- default return is number instead of string