CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [lightspd] Odd rounding issue.: Edit Log



Kenosis
User

Mar 25, 2013, 8:02 PM


Views: 468
Re: [lightspd] Odd rounding issue.

You're demonstrating an internal rounding error when moving from a floating-point representation to an integer. Place the following at the top of your script:


Code
use bignum;


Output from your code when using this module:


Code
0.29 

029


Output without it:


Code
0.29 

028


Here's the bignum documentation. Or print the value as a float--not an integer--without using the module bignum:


Code
$y = sprintf("%03.f\n", $y);



(This post was edited by Kenosis on Mar 25, 2013, 8:09 PM)


Edit Log:
Post edited by Kenosis (User) on Mar 25, 2013, 8:09 PM
Post edited by Kenosis (User) on Mar 25, 2013, 8:09 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives