SunQuest
           HTML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignHTML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 22nd, 2000, 06:40 AM
mcance mcance is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Posts: 1 mcance User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi,

I'm using the VERY simple bit of code below to add together two ints, but insted of the right answer 20.8 i get 20.799999999999997.

I have no idea whats happening here!! can any give me a hand with this one?

Cheers
Mark www.freeloader.com


code:
<html>
<head>
<title>Number Bug</title>
</head>

<script language="JavaScript">
<!--

//Just adding two floats together!!!!
var tmp = 10.6+10.2;
document.write("Adding 10.6 & 10.2 together produces; "+tmp+"<br>");

//Using the function 'nasty' to fix the error
tmp = nasty(tmp);
document.write("Using a nasty function to fix the error produces; "+tmp+"<br>");

document.close();

function nasty(fixedInt){
fixedInt = Math.round(fixedInt * 10);
return fixedInt /= 10;
}

// -->
</script>
<body>

</body>
</html>


Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignHTML Programming > float weirdness


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway