Suhayb Kharabsheh Suhayb Kharabsheh - 25 days ago 10
Javascript Question

float value extraction in javascript

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;

Answer

The simplest way I can think of is this:

var string = total.toString();
var dotidx = string.indexOf(".");
var dec = dotidx >= 0 ? +string.slice(dotidx + 1) : 0;

Notice that it doesn't work with numbers in exponential forms.