🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #16496

Math calculations

#16496
From: Kerry Helmer
Date: Tue, 16 Feb 1999 00:00
18 lines
1075 bytes
I am new to Java and I'm having a rough time understanding the math
calculations.  Here is an  examples of one of the problems that I'm having.

double tender = 99.99
centsRemain = (int)(100.00d * (tender % 1.00d));

The centsRemain variable ends up being 98 instead of 99.
When I tried to check out the problem by doing the following code:
System.out.println ((tender % 1.00d));
This returns 0.9899999999999949 instead of .99  Can someone help explain to
me what I'm doing wrong?

Does anybody have some rules to follow that would help me when performing
math operations?

Thanks
Kerry
khelmer@parlorcity.com
Technical Details
Message-ID: <7acd6l$6vc20@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,587049a5d7e832c,start
X-Google-Attributes: gidf74b3,public
From: "Kerry Helmer" <khelmer@parlorcity.com>
Subject: Math calculations
Date: 1999/02/16
Message-ID: <7acd6l$6vc20@forums.borland.com>
X-Deja-AN: 445019524
Organization: Another Netscape Collabra Server User
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
Newsgroups: borland.public.jbuilder.java.language