Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^3: Padding with sprintf changing number

by choroba (Cardinal)
on Sep 24, 2021 at 11:22 UTC ( [id://11136985]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Padding with sprintf changing number
in thread Padding with sprintf changing number

What about %016.0f?
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^4: Padding with sprintf changing number
by sachin raj aryan (Sexton) on Sep 24, 2021 at 11:34 UTC

    Thanks Alot for explanation with example and your worked perfectly i have one more Q...my $padacntnum =sprintf("%017d",$bgl) this is going to round off every number ??

      It probably is not possible to predict the results in every case. Consider these two runs of your function. Only the second replicates your original problem.
      use strict; use warnings; no warnings 'experimental::signatures'; use feature 'signatures'; sub amnt($amn) { my $amount=$_[0]; print "$amount i m checking amount before padding,\n"; my $padamnt = sprintf("%016d",$amount); print "$padamnt i m checking amount after padding,\n"; return $padamnt; } print "EXACT integer\n"; amnt(488715); print "\n\nNot quite an integer\n"; amnt(488715 - 4e-10);

      OUTPUT:

      EXACT integer 488715 i m checking amount before padding, 0000000000488715 i m checking amount after padding, Not quite an integer 488715 i m checking amount before padding, 0000000000488714 i m checking amount after padding,
      Bill

Log In?
Username:
Password:

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

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





    Results (68 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.