Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript error !!! 1

Status
Not open for further replies.

sbajoria

Programmer
Dec 9, 2003
7
0
0
IN
I have a form where i am multiplying a figure with 100 to send it to other form .
the code i m using is :
document.cpiForm.PurchaseAmount.value = document.cpiForm.PurchaseAmount.value * 100;

When i enter a value like 24.98 , The other form receives it as 2498

but when i enter a value like 34.98 , the other form receives it as 3597.9999999999995

I want it to be 3498.

I hope i am able to explain you the problem.
Can u please help me out ?

Thanks in advance
SAndeep


 
Use the Math.round or parseInt method
Code:
document.cpiForm.PurchaseAmount.value = [!]Math.round([/!]document.cpiForm.PurchaseAmount.value * 100[!])[/!];

This will only work if you are sending integer numbers and NOT floats.

[monkey][snake] <.
 
Hi..
this also doesnt work.....

i am totally stick with this....
pls help
 
I don't believe you typed it up correctly.

I did a test based on your response.

alert(34.98 * 100);

answer = 3497.9999999995

alert(Math.round(34.98 * 100));

answer = 3798

Are you sure your syntax is correct?



[monkey][snake] <.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top