-1
我想要顯示帶有兩位小數的年度租金和租金/平方。英尺也有兩位小數。我已經添加了腳本來讓這兩個字段自動顯示美元ammounts和逗號。年租金除以平方英尺顯示兩位小數點。 (即1,000.38)
任何幫助,將不勝感激!
<body>
<table border="1" width="620" style="width: 620px; height: 58px">
<tr>
<td width="82" align="center" height="16"><font face="Arial" size="2">Sq.
Ft.</font></td>
<td width="90" align="center" height="16"><font face="Arial" size="2">Annual
Rent</font></td>
<td align="center" height="16" style="width: 104px"><font face="Arial" size="2">
Rent/Sq. Ft.</font></td>
</tr>
<tr>
<td width="82" align="center"><font face="Arial" size="2">
<input type="text" name="SF_Tenant1" id="sqft1" OnKeyUp="calcRentSQFTOne()"
size="10" value="Sq. Ft.:" tabindex="602" class="style4"></font></td>
<td width="90" align="center"><font face="Arial" size="2"><input type="text"
name="AnnualRent_Tenant1" id="annualrent1" OnKeyUp="calcRentSQFTOne()" size="11"
value="Annual Rent:" tabindex="604"></font></td>
<td align="center" style="width: 104px;"><font face="Arial" size="2">
<input type="text" name="RentSF_Tenant1" id="rentsqft1"
readonly="readonly" size="11" value="Rent/Sq. Ft.:" tabindex="605"></font></td>
</tr>
</table>
<input type="submit"
value="Save" name="Save" tabindex="999" style="font-family: Arial;
font-size: 10pt; width: 65px; height: 29px;"></font></p>
<script type="text/javascript">
//calculation script
function calcRentSQFTOne(){
SquareFeet1 = document.getElementById("sqft1").value;
AnnualRent1 = document.getElementById("annualrent1").value;
document.getElementById("rentsqft1").value =
(AnnualRent1 * 1)
/(SquareFeet1 * 1);
}
//Dollar format
function formatNumber(number, digits, decimalPlaces, withCommas)
{
number = number.toString();
var simpleNumber = '';
// Strips out the dollar sign and commas.
for (var i = 0; i < number.length; ++i)
{
if (".".indexOf(number.charAt(i)) >= 0)
simpleNumber += number.charAt(i);
}
number = parseFloat(simpleNumber);
if (isNaN(number)) number = 0;
if (withCommas == null) withCommas = false;
if (digits == 0) digits = 1;
var integerPart = (decimalPlaces > 0 ? Math.floor(number) : Math.round(number));
var string = "";
for (var i = 0; i < digits || integerPart > 0; ++i)
{
// Insert a comma every three digits.
if (withCommas && string.match(/^\d\d\d/))
string = "," + string;
string = (integerPart % 10) + string;
integerPart = Math.floor(integerPart/10);
}
if (decimalPlaces > 0)
{
number -= Math.floor(number);
number *= Math.pow(10, decimalPlaces);
string += "." + formatNumber(number, decimalPlaces, 0);
}
return string;
}
</script>
</body>