-3

How to split decimal to alert(

cm = 14*2.55;
outputCMVal = Math.round(cm*10)/10;
alert(outputCMVal); //35.7

arrDecimal = outputCMVal.split('.');
alert(arrDecimal[1]); //want to alert 7 from outputCMVal

http://jsfiddle.net/iwebsmile/2Lenx3es/

2 Answers2

3

split() Method is a member of string. Since outputCMVal is a number, you need to call .toString() method before .split('.')

arrDecimal = outputCMVal.toString().split('.');

Demo: http://jsfiddle.net/91m6kmqw/

ekad
  • 14,436
  • 26
  • 44
  • 46
0

jsFiddle demo

Concatenate it to String before splitting by Character .

var cm = 14*2.55;
var outputCMVal = Math.round(cm*10)/10;
alert(outputCMVal);                              // 35.7

var arrDecimal = (outputCMVal+"").split('.');    
alert(arrDecimal[1]);                            // 7

also assign your var

Roko C. Buljan
  • 196,159
  • 39
  • 305
  • 313