develooper Front page | perl.perl5.porters | Postings from October 2003

Re: [perl #24092] sprintf problem

Thread Previous | Thread Next
From:
Nick Ing-Simmons
Date:
October 6, 2003 05:44
Subject:
Re: [perl #24092] sprintf problem
Message ID:
20031006124424.2483.4@llama.elixent.com
Alex <perl5-porters@perl.org> writes:
># New Ticket Created by  Alex 
># Please include the string:  [perl #24092]
># in the subject line of all future correspondence about this issue. 
># <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=24092 >
>
>
>Hello guys,
>
>I try to round 1.045 on my Perl (v5.6.1) but output is very strange:
>perl -e "print sprintf('%.2f', '1.045')"

But:

perl -e "print sprintf('%.20f', '1.045')"
1.04499999999999992895

The boundary is drawn an 5 in next digit down so that falls under it.

>1.04
>perl -e "print sprintf('%.2f', '1.0451')"
>1.05
>Is it the bug?
>Thanks.
>
>---
>Alex


Thread Previous | Thread Next


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