rixlabs
asked on
How to extract decimal value from string
hi all,
need to extract decimal value from a string...
example: the price is [$1000.10]
I wanto to extract only the decimal number...
p.s. Sorry for the bad english
need to extract decimal value from a string...
example: the price is [$1000.10]
I wanto to extract only the decimal number...
p.s. Sorry for the bad english
val = "$3.05";
if(val.length > 0 && val.charAt(0) == '$')val = val.substring(1);
val = parseFloat(val);
alert(val + 0.5);
if(val.length > 0 && val.charAt(0) == '$')val = val.substring(1);
val = parseFloat(val);
alert(val + 0.5);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
1.
var num = "$1000.10";
var dec = parseFloat(num) - parseInt(num);
alert('The decimal part of ' + num + ' is ' + dec);
2.
var num = "$1000.10";
var dec = new Array();
dec = num.split('.');
alert('The decimal part of ' + num + ' is ' + dec[1]);
var num = "$1000.10";
var dec = parseFloat(num) - parseInt(num);
alert('The decimal part of ' + num + ' is ' + dec);
2.
var num = "$1000.10";
var dec = new Array();
dec = num.split('.');
alert('The decimal part of ' + num + ' is ' + dec[1]);
if(val.length > 0 && val.charAt(0) == '$')val = val.substring(1);