Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re: Arithmetics

Re: Arithmetics

From: Mladen Gogala <mgogala_at_adelphia.net>
Date: Wed, 03 Dec 2003 03:44:24 -0800
Message-ID: <F001.005D8892.20031203034424@fatcity.com>


That is because you don't use printf/ sprintf. Printf/sprintf helps you handle this thing correctly. Try executing the following code:



#!/usr/bin/perl -w
use strict;
my $x=1.999999999999999999999;

my $y=sprintf("%3.2f",$x);
print "$y\n";

The result will be "2.0".

Herzliche Gruessen.

On 2003.12.03 05:54, Stefan Jahnke wrote:
> Hi list
>
> In PL/SQL, 174413 - 169281.6 (as FLOAT) results in 5131.4 as it should.
> In Perl, it results in 5131.39999999999. In C++ (GCC on both Linux and MS
> Windows) it results in 5131.4.
> I find it pretty irritating that perl doesn't handle that correctly.
> I know, it's always a problem with floating point arithmetics, but how is
> it, that perl already says good bye to accurate results while PL/SQL and C
> both still give the correct result ?
> Is there any work around or something I have to consider when doing floating
> point arithmetics in Perl ?
> I need to have accurate values without rounding them for statistic
> calculations.
>
> TIA,
> Stefan
>
>
> --
> Please see the official ORACLE-L FAQ: http://www.orafaq.net
> --
> Author: Stefan Jahnke
> INET: Stefan.Jahnke_at_bov.de
>
> Fat City Network Services -- 858-538-5051 http://www.fatcity.com
> San Diego, California -- Mailing list and web hosting services
> ---------------------------------------------------------------------
> To REMOVE yourself from this mailing list, send an E-Mail message
> to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
> the message BODY, include a line containing: UNSUB ORACLE-L
> (or the name of mailing list you want to be removed from). You may
> also send the HELP command for other information (like subscribing).
>

-- 
Mladen Gogala
Oracle DBA
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.net
-- 
Author: Mladen Gogala
  INET: mgogala_at_adelphia.net

Fat City Network Services    -- 858-538-5051 http://www.fatcity.com
San Diego, California        -- Mailing list and web hosting services
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
Received on Wed Dec 03 2003 - 05:44:24 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US