Javascript double datatype needed ?

Posted on 2009-04-14
Last Modified: 2012-05-06
Hi ,
I have a value which converts into NaN while converting using parseFloat() function ,but as of the value range is more its not working.

So is there any other alternate like "parseDouble()" or sort of or any other suggestion or logic to handle this.

eg when I convert parseFloat('123456789.565') then it returns NaN. please help me.

Thanks in Advance.
function add()
     var ch1 = '1212154.45'; //Comes from textbox
     var ch2 = '1212154454.45'; //Comes from textbox
           alert(parseFloat(ch1) ) // returns NaN
     var total = parseFloat(ch1) + parseFloat(ch2)

Open in new window

Question by:vikasbapat
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
  • 3
LVL 31

Accepted Solution

GwynforWeb earned 250 total points
ID: 24139306
Use the function isNaN() to detect if they are valid numbers and simple convert to rels by multiplying by 1

function add()
     var ch1 = '1212154.45'; //Comes from textbox
     var ch2 = '1212154454.45'; //Comes from textbox
      if (isNaN(ch1) || isNaN(ch2) ) return 'not valid'
      return 1*ch1 + 1*ch2
LVL 20

Expert Comment

ID: 24139324
Normally I have read somewhere, that they should convert automatically when used with a mathematical operation.
LVL 31

Expert Comment

ID: 24139365
typo, should read  'reals'  not  'rels'"

Author Closing Comment

ID: 31569949
ok thank you  i will try that example
LVL 31

Expert Comment

ID: 24206451
A B grade? I think I have answered the question exactly?

Featured Post

Industry Leaders: 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

Suggested Solutions

Title # Comments Views Activity
How to combine and minify CSS and JS files 5 36
Need help with this homework problem. 5 54
Video Tutorial help 2 37
Session on Html 8 38
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
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…

740 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