develooper Front page | perl.beginners | Postings from August 2009

AW: WELCOME to beginners@perl.org

Thread Previous
From:
Thomas Bätzler
Date:
August 21, 2009 03:47
Subject:
AW: WELCOME to beginners@perl.org
Message ID:
E350C77ABFDBD242BDD51F5DA07905C102826AE5@SONNE.gw.bringe.net
Ajay Kumar <akumar@securities.com> asked:
> Gesendet: Freitag, 21. August 2009 12:23
> An: beginners@perl.org
> Betreff: RE: WELCOME to beginners@perl.org
> 
>  Hi All
> 
> I have great issues
> 
> 1) perl -e '$a=0.123451005;$a=sprintf("%.8f",$a);print"=$a\n";'
> Output=0.12345101
> 2) perl -e '$a=5.123451005;$a=sprintf("%.8f",$a);print"=$a\n";'
> Output=5.12345100
> 
> 
> Here 1 one ging correct result but the second one wrong result
> For second one result should be 5.12345101 but it is giving 5.12345100
> 
> 
> May I know  why it behabe So

See the first question in the Data: Number section of http://perldoc.perl.org/perlfaq4.html 

For the gritty details, see the article http://en.wikipedia.org/wiki/Floating_point and especially its setion "representable numbers" at Wikipedia.

HTH,
Thomas

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About