473,385 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

calculation error 55 - 0.04 = 54.96000000000123

228 100+
[html]<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>game</title>
<script language='javascript'><!--

var t = 60;

var int=self.setInterval("clock()",40)
function clock()
{
t = t-0.04; // ===========PROBLEM IS HERE=============


document.getElementById("clock").innerHTML=t;

}

--></script>
</head>
<body>
<span id='clock'></span>
</body>
</html>[/html]
whats wrong with THIS CALCULATION?
did i do something wrong or is that a bag?

Any help and ideas apreciated

regards
jx2
Aug 17 '07 #1
3 1771
pbmods
5,821 Expert 4TB
Heya, JX2.

All languages have floating-point accuracy issues.

The easiest way around this is to multiply everything by 100:
Expand|Select|Wrap|Line Numbers
  1. var t = 6000;
  2.  
  3.     var int=self.setInterval("clock()",40)
  4. function clock()
  5.   {
  6.     t -= 4;
  7.     document.getElementById("clock").innerHTML=t;
  8.   }
  9.  
Aug 18 '07 #2
jx2
228 100+
yeah i know - i did as you said - but how is it posible? its **** maths isnt it?

regards jx2
Aug 18 '07 #3
acoder
16,027 Expert Mod 8TB
Read about floating point accuracy problems.
Aug 18 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: JStrauss | last post by:
Hello, I am having a problem getting some code to calculate/work in an ASP page. In the snippet below I am collecting some data (inthours1 and intrate1) and then want to calculate a value...
5
by: Michael Hagstrom | last post by:
Good Day - I have written a form which collects input for a fare calculation. The form collects the following: 1) Departure or Destination Group (1,2,or 3) 2) Number of Adults 3) Number of...
9
by: BaWork | last post by:
I'm using the following code to calculate order amount in a payment form for Authorize.net: (Assume book_copies = 1 and ship_country = United States) book_copies = request ("book_copies")...
4
by: vg-mail | last post by:
Hello all, I have identical design for form and report but I am getting calculation error on form and everything is OK on report. The form and report are build up on SQL statement. The...
4
by: heckstein | last post by:
I am a novice working in Access 2002 trying to run a query I created. I am receiving the error "scaling of decimal value resulted in data trunction", which I have determined is due to this...
6
by: David | last post by:
Hi, I have the following calculation I am trying to work out ..... Not sure how ? Variable 1 = minstock Variable 2 = oDict(oKey) I need to test if my variable 'minstock' <= 40% of...
10
by: 60325 | last post by:
This is the page where I collect the data in drop-down boxes with values of 1-10 and send it to a submitted page to do calculations. Example: Employee1 TeamScore(1-10) Employee2 ...
3
by: mattmao | last post by:
Okay, I was asked by a friend about the result of this limit: http://bbs.newwise.com/attdata/forumid_14/20070922_fe7f77c81050413a20fbDWYOGm7zeRj3.jpg Not n->zero but n-> + infinite I really...
2
by: edcha | last post by:
I am trying to use the following Aggregate Calculation. string time = trabajadoresTable.Compute ( "Sum(DateTime)" , "") .ToString(); I need to sum the hours in a column with type DateTime. If...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.