473,383 Members | 1,958 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,383 software developers and data experts.

Double+Int16

Hi,
I am having a bit of a resolution problem.
I have a form that accepts elapsed time in various formats including 1.5 and
1:30

and converting it to minutes but I am getting a resolution problem.

Can someone explain this to me, my code:
dblMins = Val(stLoadSOs)

intHrs = Int(dblMins)

dblMins = dblMins - intHrs

intMins = intHrs * 60 + Int(dblMins * intTim)

if the input is '1:20' then the unshown code sets

stLoadSOs = "1.20" and intTim = 100

dblMins = 1.2 (correctly)

intHrs = 1 (correctly)

but then dblMins = dblMins - intHrs shows 19.999999 (incorrectly)

1.2 - 1 should equal 0.2

What is causing this resolution problem?

Thanks

Doug

Jul 21 '05 #1
2 1263
Doug Bell <du*@bigpond.com> wrote:
I am having a bit of a resolution problem.
I have a form that accepts elapsed time in various formats including 1.5 and
1:30

and converting it to minutes but I am getting a resolution problem.

Can someone explain this to me, my code:
dblMins = Val(stLoadSOs)

intHrs = Int(dblMins)

dblMins = dblMins - intHrs

intMins = intHrs * 60 + Int(dblMins * intTim)

if the input is '1:20' then the unshown code sets

stLoadSOs = "1.20" and intTim = 100

dblMins = 1.2 (correctly)

intHrs = 1 (correctly)

but then dblMins = dblMins - intHrs shows 19.999999 (incorrectly)

1.2 - 1 should equal 0.2

What is causing this resolution problem?


Your misunderstanding of floating point numbers is faulty.

dblMins isn't actually 1.2, as that isn't representable in binary
floating point. That's just how the debugger (or whatever) is showing
it.

See http://www.pobox.com/~skeet/csharp/floatingpoint.html

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
Thanks Jon

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Doug Bell <du*@bigpond.com> wrote:
I am having a bit of a resolution problem.
I have a form that accepts elapsed time in various formats including 1.5 and 1:30

and converting it to minutes but I am getting a resolution problem.

Can someone explain this to me, my code:
dblMins = Val(stLoadSOs)

intHrs = Int(dblMins)

dblMins = dblMins - intHrs

intMins = intHrs * 60 + Int(dblMins * intTim)

if the input is '1:20' then the unshown code sets

stLoadSOs = "1.20" and intTim = 100

dblMins = 1.2 (correctly)

intHrs = 1 (correctly)

but then dblMins = dblMins - intHrs shows 19.999999 (incorrectly)

1.2 - 1 should equal 0.2

What is causing this resolution problem?


Your misunderstanding of floating point numbers is faulty.

dblMins isn't actually 1.2, as that isn't representable in binary
floating point. That's just how the debugger (or whatever) is showing
it.

See http://www.pobox.com/~skeet/csharp/floatingpoint.html

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jim Heavey | last post by:
If I am building a DataTable for a SQL Result set and I have SQL datatype of Binary Image SmallMoney VarBinary and setting the dataTable.Column.Type property, what "Type" do I set it to? ...
2
by: ORC | last post by:
What is the difference between: Convert.ToDouble(Int16number); and: (double)Int16number; ? and which is the fastest? Thanks Ole
5
by: rk | last post by:
Folks, Any comment on why these types (Double, Int16 etc.) are struct but not a class. I was trying to pass an object type to a method that takes Double hoping that it will work but just...
2
by: Doug Bell | last post by:
Hi, I am having a bit of a resolution problem. I have a form that accepts elapsed time in various formats including 1.5 and 1:30 and converting it to minutes but I am getting a resolution...
2
by: Web learner | last post by:
At line unitsInStock.Add((double)dr.GetValue(1)); I get same error: Specified cast is not valid If you comment out above code line and also Response.Write(unitsInStock); then the code works...
6
by: Steve | last post by:
Hi, I've developed a testing application that stores formatted results in a database. Recently it was requested that I add the ability to generate graphs from the raw, un formatted test results...
17
by: Terry | last post by:
I have some old VB5 functions that specify types of Long and Double that make calls to an unmanaged 3rd party DLL probably just as old. The source for the DLL is not available. I'm getting some...
104
by: JohnQ | last post by:
Well apparently not since one can step thru template code with a debugger. But if I was willing to make the concession on debugging, templates would be strictly a precompiler thing? I have a...
2
by: jobs | last post by:
What's messed up here is that i have close to identical code that is working perfectly, only difference is that code uses sqldatasource control instead objectdatasource used here. Getting this...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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
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?
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...

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.