|
Hi,
I've written a small calculation in javascript.
In below example, it consists of 3 textfields and 1 button.
On click of calculate button, it multiplies of textfield1 and textfield2 and displays on textfield3.
But it doesn't show proper multiplication.
For example:
1548 * 17.01 = 26331.48
But it shows as 26331.480000000003
similarly,
1441 * 19.03 = 26331.48
But it shows as 27422.230000000003
It is adding another 10 decimals...
I can use round off method by using toFixed, but i can't change for each and every page of my project.
Can anyone help me regarding the same
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<script language="JavaScript" type="text/javascript">
function toMul()
{
document.getElementById("text3").value = document.getElementById("text1").value * document.getElementById("text2").value;
}
</Script>
<TITLE></TITLE>
</HEAD>
<BODY>
<FORM METHOD="POST" NAME="MUL1" >
<P>Enter Numbers <INPUT id=text1
style="LEFT: 113px; TOP: 16px" name=text1><INPUT id=text2 name=text2></P>
<P><INPUT id=button1 type=button value=Calculate name=Calculate onClick="toMul()"></P>
<P>Output <INPUT id=text3 name=text3></P>
</FORM>
</BODY>
</HTML>
|
|
|
|
|
|
|
// |