in reply to Padding with sprintf changing number
#! /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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Padding with sprintf changing number
by sachin raj aryan (Sexton) on Sep 24, 2021 at 11:19 UTC | |
by choroba (Cardinal) on Sep 24, 2021 at 11:22 UTC | |
by sachin raj aryan (Sexton) on Sep 24, 2021 at 11:34 UTC | |
by BillKSmith (Monsignor) on Sep 24, 2021 at 17:11 UTC |