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
LVL 3
rixlabsAsked:
Who is Participating?
 
system_downCommented:
Hi,

var str = "the price is [$1000.10]";
var reg = /\[\$(\d*.\d*)\]/;
ar = reg.exec(str);
      
alert(ar[1]);

S_D
0
 
enachemcCommented:
val = "$3.05";
if(val.length > 0 && val.charAt(0) == '$')val = val.substring(1);
0
 
enachemcCommented:
val = "$3.05";
if(val.length > 0 && val.charAt(0) == '$')val = val.substring(1);
val = parseFloat(val);
alert(val + 0.5);
0
 
MasoudghCommented:
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]);
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.