|
|
|
start date: Wed, 22 Aug 2007 14:43:59 -0500,
posted on: microsoft.public.dotnet.framework.aspnet
back
| Thread Index |
|
1
David C
|
|
2
Jesse Houwing am
|
Javascript calc in asp.net page wrong
I have a Javascript function in my aspx page that gives me a different
answer than my calculator. For example, using a price of 415,000.00 and a
Size of 11,200 in my 2 controls I am trying to calculate the price per sq
ft. My Javascript comes up with 37.73 and my calculator comes up with 37.05
and i don't know why. Can anyone help? Below is my Javascript that
references these controls on my aspx page:
function calcpriceper()
{
var otxtsaleprice = document.getElementById('fvProperty_txtSalePrice');
var otxttotalsize = document.getElementById('fvProperty_txtTotalSize');
if (otxtsaleprice.value != '' && otxttotalsize.value != '')
{
var pricepersqft = (parseFloat(otxtsaleprice.value) /
parseFloat(otxttotalsize.value));
//alert('Price/Sq Ft = ' + Math.round(pricepersqft*100)/100);
var osq = document.getElementById('fvProperty_txtsqftprice');
osq.value = (Math.round(pricepersqft*100)/100);
}
}
David
Date:Wed, 22 Aug 2007 14:43:59 -0500
Author:
|
Re: Javascript calc in asp.net page wrong
Hello David,
> I have a Javascript function in my aspx page that gives me a different
> answer than my calculator. For example, using a price of 415,000.00
> and a Size of 11,200 in my 2 controls I am trying to calculate the
> price per sq ft. My Javascript comes up with 37.73 and my calculator
> comes up with 37.05 and i don't know why. Can anyone help? Below is
> my Javascript that references these controls on my aspx page:
>
> function calcpriceper()
>
> {
>
> var otxtsaleprice =
> document.getElementById('fvProperty_txtSalePrice');
>
> var otxttotalsize =
> document.getElementById('fvProperty_txtTotalSize');
>
> if (otxtsaleprice.value != '' && otxttotalsize.value != '')
>
> {
>
> var pricepersqft = (parseFloat(otxtsaleprice.value) /
> parseFloat(otxttotalsize.value));
>
> //alert('Price/Sq Ft = ' + Math.round(pricepersqft*100)/100);
>
> var osq = document.getElementById('fvProperty_txtsqftprice');
>
> osq.value = (Math.round(pricepersqft*100)/100);
>
> }
>
> }
>
> David
>
I pasted this into the firefox javascript console and it comes up with the
expected value.
alert(Math.round(('415000'*1)/('11200'*1)*100)/100);
What are the contents of your parseFloat, method?
--
Jesse Houwing
jesse.houwing at sogeti.nl
Date:Wed, 22 Aug 2007 22:03:27 +0000 (UTC)
Author:
|
|
|