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

Popular posts from this blog

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

arrays - Algorithm to find ideal starting spot in a circle -

php - Autoloader issue not returning Class -