codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Multiplication Problem  Gag at 09:39 on Thursday, January 25, 2007
 

hi,
I am doing some calculation in javascript. Lets say
a=25, b=161.2;

when I multiply these these in Javascript as below:
var result= parseFloat(a)*parseFloat(b);

it gives the answer 4029.99999999995.

But if you check it must give the result 4030.00.

I dont understand why javascript is doing internal manipulation to the result.
And how can I get the expected result.

If anybody knows something about this, plz do help me asap.

  Re: Multiplication Problem  mmarab at 12:24 on Thursday, January 25, 2007
 

Hi

I am not a javascript expert, but one thing i noticed is that you parse "a" which contains the value of 25 as a float, and its not a floating point number. Could you just parse it as an integer! That may increase the accurracy of the calculation.



  Re: Multiplication Problem  Gag at 02:58 on Monday, January 29, 2007
 

hi,
Thanks for replying. As you said, I have tried using parseInt() also, but the problem still exists. There might be some other solution to this problem.








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: date calculation
•  Re: JTable..
•  Re: Multiplication Problem
•  forum skin code
•  Using Fork in Perl
•  Re: import contacts of msn/yahoo
•  Re: Files
•  Re: Manipulating large Images.
•  Re: Replacing Class definition comments in java files


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2007