Page 1 of 1

NaN problem

Posted: Tue Mar 06, 2007 11:07 am
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>

Posted: Tue Mar 06, 2007 11:12 am
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.

Posted: Tue Mar 06, 2007 11:16 am
by sarris
thanks!!
replaced it and then parsed it and worked.pretty weird i have to say