in reply to Padding with sprintf changing number
I tried it with 1/3:
#! /usr/bin/perl use warnings; use strict; use feature qw{ say }; sub amnt { my ($amount) = @_; say "$amount I'm checking amount before padding"; my $padamnt = sprintf("%016d",$amount); say "$padamnt I'm checking amount after padding"; } amnt(1/3);
As expected, before padding its 0.333333333333333, after padding it's 0000000000000000. Rounding.
Now try it with 1.999999999999999. print doesn't output the precise value.
2 I'm checking amount before padding 0000000000000001 I'm checking amount after padding
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Padding with sprintf changing number
by sachin raj aryan (Acolyte) on Sep 24, 2021 at 11:19 UTC | |
by choroba (Cardinal) on Sep 24, 2021 at 11:22 UTC | |
by sachin raj aryan (Acolyte) on Sep 24, 2021 at 11:34 UTC | |
by BillKSmith (Monsignor) on Sep 24, 2021 at 17:11 UTC |
In Section
Seekers of Perl Wisdom