Link to home
Start Free TrialLog in
Avatar of rixlabs
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
Avatar of enachemc
enachemc
Flag of Afghanistan image

val = "$3.05";
if(val.length > 0 && val.charAt(0) == '$')val = val.substring(1);
val = "$3.05";
if(val.length > 0 && val.charAt(0) == '$')val = val.substring(1);
val = parseFloat(val);
alert(val + 0.5);
ASKER CERTIFIED SOLUTION
Avatar of system_down
system_down
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Masoudgh
Masoudgh

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]);