Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Padding with sprintf changing number

by Marshall (Canon)
on Sep 24, 2021 at 21:36 UTC ( [id://11137002]=note: print w/replies, xml ) Need Help??


in reply to Padding with sprintf changing number

As another thought for you...consider the use of functions in the POSIX module to specify exactly what you want.
Of interest: "ceil", "floor", "lround", "modf", "round", "trunc".

Some of the these functions didn't appear until Perl 5.22. So the newer functions could be an issue if you have an old Perl.

Also read the documentation carefully. Some of these functions return an actual integer. Some return a float with the fractional part set to zero.

These functions should be pretty fast (at least they are in C). In some cases, it might be appropriate to call one of these functions to make it crystal clear to the reader your exact intent even though you might follow it with some kind of printf or sprintf.

  • Comment on Re: Padding with sprintf changing number

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11137002]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2025-11-18 03:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (72 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.