NaN problem

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
sarris
Forum Contributor
Posts: 137
Joined: Mon Dec 04, 2006 2:44 pm

NaN problem

Post by sarris »

Hi there
I am getting a value from an xml using DOM in that manner.

Code: Select all

tempInterest = tempProg.getElementsByTagName("Interest")[0].childNodes[0].nodeValue;
i am trying then to print it on a textbox.
if i leave it as it is, the value in the textbox is 3,53 and not 3.53

if i try to make calculations with that number (tempInterest) and then print it to a textbox it shows NaN.
That i guess means that the value passes as String and not as double.
I tried this

Code: Select all

tempInterest = parseFloat(tempProg.getElementsByTagName("Interest")[0].childNodes[0].nodeValue);
and the number became 3 from 3,53
i tried this as well

Code: Select all

tempInterest = Number(tempProg.getElementsByTagName("Interest")[0].childNodes[0].nodeValue);
and got NaN again

The thing is that in the xml i have the numbers as 3.45 3.12 etc not with commas ( , )
Why are they passed to tempInterest with commas?

Code: Select all

 <Program>
  <Name>Program1</Name> 
  <Interest>3.53</Interest> 
  </Program>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It may have to do with your browser's current locale and/or some locale information embedded in the XML.

Worst case, you can perform a replacement on the value then parse it.
sarris
Forum Contributor
Posts: 137
Joined: Mon Dec 04, 2006 2:44 pm

Post by sarris »

thanks!!
replaced it and then parsed it and worked.pretty weird i have to say
Post Reply