Solved

How to extract decimal value from string

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

733 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