计算器站点2位小数

时间:2015-03-10 22:43:12

标签: javascript html forms

您好,我正在建立一个网站,以帮助我的商店在更长的时间内更快地计算产品成本。

我遇到了结果框的问题,当我填写表单并单击计算时,它给出了小数位加载的答案。

无论如何,我可以将其更改为2位小数。

这是我的代码:

<html>
<head>
<title>phone</title>

<script type="text/javascript">
function calcform()
{
with (document.form1)
{ result.value = +number1.value + +number2.value * 24}
{ monthly.value = +result.value / 24}}

</script>

<style type="text/css">
.auto-style1 {
font-size: x-large;
font-family: "Courier New", Courier, monospace;
font-weight: bold;
text-align: center;
}
.auto-style2 {
text-align: center;
}
</style>

</head>
<body bgcolor="#00274c" leftmargin="0" topmargin="0" marginwidth="0"     marginheight="0" onLoad="calculate();">
<p align="center">
<table id="Table_01" width="360" height="594" border="0" cellpadding="0"     cellspacing="0">
<form name="form1" action="">   
<tr>
    <td colspan="5">
        <img src="images/phone_01.jpg" width="360" height="150" alt=""></td>
</tr>
<tr>
    <td rowspan="8">
        <img src="images/phone_02.jpg" width="24" height="382" alt=""></td>
    <td colspan="3" background="images/pc.jpg" width="311" height="45" >
        <center class="auto-style2">
            <input type="text" id="number1" value="" size="40" class="auto-style1" style="height: 40px; width: 300px" /></form></td>
    <td rowspan="8">
        <img src="images/phone_04.jpg" width="25" height="382" alt=""></td>
</tr>
<tr>
    <td colspan="3">
        <img src="images/phone_05.jpg" width="311" height="54" alt=""></td>
</tr>
<tr>
    <td colspan="3" background="images/amt.jpg" width="311" height="47" class="auto-style1">
        <input type="text" id="number2" value="" size="40" class="auto-style1" style="height: 40px; width: 300px" /></td>
</tr>
<tr>
    <td colspan="3">
        <img src="images/phone_07.jpg" width="311" height="52" alt=""></td>
</tr>
<tr>

<td colspan="3" background="images/tc.jpg" width="311" height="46" class="auto-style1">
        <center><strong>
        <input type="text" id="result" value="" size="40" class="auto-style1" style="height: 40px; width: 300px" /><br class="auto-style1"/>
        </strong></td>
</tr>
<tr>
    <td colspan="3">
        <img src="images/phone_09.jpg" width="311" height="50" alt=""></td>
</tr>
<tr>


<td colspan="3" background="images/nmc.jpg" width="311" height="42" class="auto-style1">
        <center><strong>
  <input type="text" id="monthly" size="40" class="auto-style1" style="height: 40px; width: 300px"/><br class="auto-style1"/>
  </strong></td>
</tr>
<tr>
    <td>
        <img src="images/phone_11.jpg" width="83" height="46" alt=""></td>

<td width="143" height="46">
        <input type="image" src="images/cal.jpg" id="Calculate" value="Calculate" onclick="calcform()"/></td>
    <td>
        <img src="images/phone_13.jpg" width="85" height="46" alt=""></td>
</tr>
<tr>
    <td colspan="5">
        <img src="images/phone_14.jpg" width="360" height="62" alt=""></td>
</tr>
</table>


</body>
</html>

请帮助我好好看几天,这让我很生气。

提前谢谢

理查德

0 个答案:

没有答案