how can i extract float value like (0.9) to be a whole integer value (9) in JavaScript?
example
var total = 67.9;
something to process var whole var DEC to be like
var whole = 67;
var DEC = 9;
There are many ways to find a result. I give you one simple solution.
var total = 67.9
var splitVal = total.toString().split(".")
var whole = splitVal[0], var desc = splitVal[1] || 0
and if you want to convert whole and desc in number then multiply by 1.
var whole = splitVal[0] * 1
undefined/NaN if total is actually an integer.var desc = splitVal[1] || 0. Thanks MaxArt
dec = 321?var total = 67.9;--- well, in the question they are dealing with numbers not strings. Since not every number is correctly representable - you cannot tell (in runtime) whether the numeric literal and its string representation are the same thing.