We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents f216702 + cd8d6ae commit 1a90373Copy full SHA for 1a90373
src/HLL/sprintf.nqp
@@ -418,6 +418,7 @@ my module sprintf {
418
my $pre := '0' if $int ne '0' && has_flag($/, 'hash');
419
if nqp::chars($<precision>) {
420
$int := '' if $<precision>.made == 0 && $int == 0;
421
+ $pre := '' if $<precision>.made > nqp::chars($int);
422
$int := $pre ~ infix_x('0', intify($<precision>.made) - nqp::chars($int)) ~ $int;
423
}
424
else {
t/hll/06-sprintf.t
@@ -22,7 +22,7 @@ sub is($actual, $expected, $description) {
22
23
24
25
-plan(280);
+plan(284);
26
27
is(nqp::sprintf('Walter Bishop', []), 'Walter Bishop', 'no directives' );
28
@@ -89,6 +89,10 @@ is(nqp::sprintf('%o', [12]), '14', 'simple %o');
89
is(nqp::sprintf('%o', [22.01]), '26', 'decimal %o');
90
is(nqp::sprintf('%06o', [127]), '000177', '%o with 0-padding');
91
is(nqp::sprintf('%#6o', [127]), ' 0177', '%o with space-padding and leading 0');
92
+is(nqp::sprintf('%.5o', [83]), '00123', '%o with precision');
93
+is(nqp::sprintf('%#.5o', [83]), '00123', '%o with precision, leading 0 not required');
94
+is(nqp::sprintf('%.5o', [5349]), '12345', '%o with insufficient precision');
95
+is(nqp::sprintf('%#.5o', [5349]), '012345', '%o with precision, required leading 0 added');
96
97
is(nqp::sprintf('%x', [0]), '0', 'simple %x');
98
is(nqp::sprintf('%x', [12]), 'c', 'simple %x');
0 commit comments