Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: Need help with parseFloat()


Message #1 by John Owen <JOWEN@f...> on Thu, 19 Jul 2001 10:42:37 -0500
Alex, I found the final error. Your function is great. :) I didn't notice
there was a Math library in Javascript. I was rounding all my values except
in one calculation. Once I rounded there, problem solved. What I find weird
is when I was evaluating (with alert) the values, they looked ok (rounded
precisely). However, when I added the rounded values, sooner or later the
precision was lost. So basically, I had to round each value similar to this
:

for(var i = 0; i < maxItems; i++)
{
  sValue = sValue + roundTo(newValue,roundFactor);
}
sValue = roundTo(sValue); // even though newValue was previously rounded
chargesForm.runningTtl.value = sValue.toString;

Thanks again. :)

John Owen
Federal TransTel
Senior Developer


-----Original Message-----
From: Alex Shiell, ITS, EC, SE [mailto:alex.shiell@s...]
Sent: Friday, July 20, 2001 3:45 AM
To: javascript
Subject: [javascript] RE: Need help with parseFloat()


what happens when you do an implicit conversion?

e.g.
 chargesForm.runningTtl.value = sValue


-----Original Message-----
From: John Owen [mailto:JOWEN@f...]
Sent: 19 July 2001 20:08
To: javascript
Subject: [javascript] RE: Need help with parseFloat()


Thanks for the function Alex. :)

However, it seems the problem occurs when I execute the following statement
:

  chargesForm.runningTtl.value = sValue.toString();

I alert sValue before this statement and it is fine (ie, 4.53) but when
sValue.toString() or String(sValue) is called, chargesForm.runningTtl.value
gets 4.529999999999.

Any ideas? I'm so close to finishing this screen and this is the only thing
holding me back. :)

Thanks,

John Owen
Federal TransTel
Senior Developer





  Return to Index