Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General 2 / November 2006



Tip: Looking for answers? Try searching our database.

debug.print 183 - 173.55

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
xgold - 28 Nov 2006 22:19 GMT
i have visual basig 6

if i type in the debug window it gives me a strange result

debug.print 183 - 173.55
9.44999999999999

why this result instead of 9.45

the same is happening if i do
a  = 183
b = 173.55
c = a-b
debug.print c

if i do 183 - 174.55 or 183 - 180.55 the same strange thing happen. (  with
.449999999 instead of .45 )why and how to avoid this?
if you try this with windows standard calculator it gives the right answer.

ty
Ken Halter - 28 Nov 2006 23:20 GMT
>i have visual basig 6
>
[quoted text clipped - 4 lines]
>
> why this result instead of 9.45

This question is as old as floating point math itself

> if you try this with windows standard calculator it gives the right
> answer.

The Calculator knows how to work with floating point numbers.

Weird floating point problem
http://groups.google.com.my/group/microsoft.public.vb.general.discussion/msg/74b
7abbe3645bd1b


Signature

Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
In Loving Memory - http://www.vbsight.com/Remembrance.htm

xgold - 29 Nov 2006 01:59 GMT
hmm strange problem , i didnt knew about that, i solved the problem using
the round function  round(c,2) , ty.

> >i have visual basig 6
> >
[quoted text clipped - 13 lines]
>
> Weird floating point problem

http://groups.google.com.my/group/microsoft.public.vb.general.discussion/msg
/74b7abbe3645bd1b

> --
> Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
> In Loving Memory - http://www.vbsight.com/Remembrance.htm
Robert Morley - 29 Nov 2006 18:46 GMT
If you're doing this in VB instead of via a query, you can also force this
to a Currency data type through a variety of methods...the simplest one (to
use your example) is:

debug.print 183@ - 173.55@

(Technically only one of the @'s is needed, but it's best to be thorough.)

If you don't mind fairly slow code, you can also use the Decimal data type:

debug.print CDec(183) - CDec(173.55)

Rob

> hmm strange problem , i didnt knew about that, i solved the problem using
> the round function  round(c,2) , ty.
[quoted text clipped - 23 lines]
>> Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
>> In Loving Memory - http://www.vbsight.com/Remembrance.htm
Robert Morley - 30 Nov 2006 02:52 GMT
> If you're doing this in VB instead of via a query, you can also force this

Sorry about the reference to a query...most of my groups are Access groups
and I hadn't clued in that I was now in the realms of VB only. :)

Rob
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.