Date: Sun, 14 Jan 2007 16:58:59 -0500
Reply-To: Richard Ristow <email@example.com>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Richard Ristow <firstname.lastname@example.org>
Subject: Re: How can I round an expression to 2 decimal points?
Content-Type: text/plain; charset="us-ascii"; format=flowed
At 08:33 AM 1/14/2007, Boika Mileva wrote:
>Actually I need my value really rounded, not only to be displayed
>rounded. I am developing a data checking syntax and need to compare an
>entered value with 2 decimal points in a particular variable, with the
>value in another (control) variable, which is a result of a
>calculation, using a formula. The second variable is with the same
>format as the first (F6.2), but its real value (the not rounded result
>of the calculation) could have more then 2 decimal points.
That brings up another issue: SPSS numeric values are stored in binary
(the 64-bit floating-point representation from standard IEEE 754), and
a lot of two-decimal numbers, numbers that are an exact multiple of
10**-2, are not represented exactly. The rounding methods that have
been posted are the best possible; but the approximate two-decimal
numbers obtained by rounding won't necessarily be identical to the
approximate two-decimal numbers from a two-decimal value read in.
. Compute rounded = RND(COMPUTED*100) / 100.
standard practice would use a test like
. DO IF ABS(INPUT-ROUNDED) > 1E-4.
. DO IF INPUT NE ROUNDED.
-Onward, and good luck,