math - float value extraction in javascript -
how can extract float value (0.9) whole integer value (9) in javascript?
example
var total = 67.9; process var whole var dec var whole = 67; var dec = 9;
the simplest way can think of this:
var string = total.tostring(); var dotidx = string.indexof("."); var dec = dotidx >= 0 ? +string.slice(dotidx + 1) : 0;
notice doesn't work numbers in exponential forms.
Comments
Post a Comment