DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
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:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us