siva shanker siva shanker - 2 months ago 6
jQuery Question

get value before point and after point using jquery


  • My value is 13652.598 , i want 2 and 5 from the value.

  • I have tried as below but taking from 1, below is my code






main_value=13652.598
arr = main_value.toString().split(".");
var firstvalue=arr['0'].substring(1,-2);
var secoundtvalue=arr['1'].substring(1,-1);


Expected firstvalue is 2 and expected secondvalue is 5.

Answer

You can do something like this

var main_value=13652.598.toString();
var _getIndex = main_value.indexOf('.')
var befChar = main_value.charAt(_getIndex-1);
var AefChar = main_value.charAt(_getIndex+1);
document.write('<pre>'+befChar+' '+AefChar+'</pre>')

JSFIDDLE

Comments