comp.lang.ada
 help / color / mirror / Atom feed
From: "Steven Deller" <deller@highstream.net>
Subject: RE: Decimals after the point
Date: Thu, 7 Nov 2002 21:50:58 -0600
Date: 2002-11-07T21:50:58-06:00	[thread overview]
Message-ID: <mailman.1036727403.20069.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: <9qhcqa.bp3.ln@beastie.ix.netcom.com>

Actually, for any binary representation, the only "2 decimal digit"
values are those for which all bits after the first two fractional bits
are zeroes, yielding all numbers that are some integer plus:
  0.00, 0.25, 0.5, 0.75
The reason for this is that 2**N divides into 10**2 evenly only for
N=0,1,2. 

So rather than test the decimal value, you only need to check the
fractional part for *equality* with the above values.  Normally equality
testing with floating point values is not advisable, but it is called
for here.

I'll leave how to capture the fractional part of a floating point value
and how to test it to you.   Hint: Read the Ada manual attributes
section.

Regards,
Steve Deller  

> -----Original Message-----
> From: comp.lang.ada-admin@ada.eu.org 
> [mailto:comp.lang.ada-admin@ada.eu.org] On Behalf Of Dennis Lee Bieber
> Sent: Wednesday, November 06, 2002 8:06 PM
> To: comp.lang.ada@ada.eu.org
> Subject: Re: Decimals after the point
> 
> 
> Genevieve B. fed this fish to the penguins on Wednesday 06 November 
> 2002 03:01 pm:
> 
> > Hi!
> > 
> > For a project at university, there is a bonus that is to check for 
> > only 2 decimals after the point in a float. does anybody 
> have an idea?
> > 
> > I have an idea of putting my float into a string instead and then 
> > check for the point...and then check for only 2 numbers after it...
> >
>         Probably not valid -- after all, you could code the 
> float->string 
> write operation to only write two decimal places... Hence 
> you'd always 
> see just two decimals <G>
> 
> 
>         However, the assignment is rather error-prone, due to 
> the problems of 
> decimal <> binary conversions. What was input as 1.40 may be 
> output as 
> 1.3999999. The assignment should properly specify what behavior is to 




  reply	other threads:[~2002-11-08  3:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-06 23:01 Decimals after the point Genevieve B.
2002-11-06 22:08 ` Decimals after the point (school question) Larry Kilgallen
2002-11-07  2:06 ` Decimals after the point Dennis Lee Bieber
2002-11-08  3:50   ` Steven Deller [this message]
2002-11-09  5:08 ` SteveD
2002-11-18  1:35   ` Richard Riehle
2002-11-18  5:17     ` Dennis Lee Bieber
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox