Solved

How to extract decimal value from string

Posted on 2006-11-30
4
1,151 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 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

696 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