?
Solved

How to extract decimal value from string

Posted on 2006-11-30
4
Medium Priority
?
1,154 Views
Last Modified: 2011-10-03
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
0
Comment
Question by:rixlabs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 12

Expert Comment

by:enachemc
ID: 18045631
val = "$3.05";
if(val.length > 0 && val.charAt(0) == '$')val = val.substring(1);
0
 
LVL 12

Expert Comment

by:enachemc
ID: 18045777
val = "$3.05";
if(val.length > 0 && val.charAt(0) == '$')val = val.substring(1);
val = parseFloat(val);
alert(val + 0.5);
0
 
LVL 6

Accepted Solution

by:
system_down earned 2000 total points
ID: 18045907
Hi,

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

S_D
0
 
LVL 3

Expert Comment

by:Masoudgh
ID: 18046115
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question