Attempt 1 printf("A float: %12" . ($root_beer ? ".4f" : "s") . $/, ($root_beer || '')); blech.
Attempt 2
Better, I think.if ($root_beer) { printf("A float: %12.4f$/", $root_beer); } else { printf("A float: %12s$/", ''); }
Attempt 3 printf("A float: %12s$/", $root_beer ? sprintf("%12.4f",$root_beer) : ''); Hmmm - I don't think so.
Attempt 4
That seems mildly evil. I'm sure we could golf that down a bit... ;-)my $root_beer_str = $root_beer || ''; # change 0 to blank. $root_beer_str &&= sprintf("%12.4f", $root_beer); printf("A float: %12s$/", $root_beer_str);
Attempt 5 - just because. printf("A float: %12s$/", ($root_beer || '') && sprintf("%12.4f", $root_beer)); Ewwwww.... :-)
In reply to Re: Blankety-Blank Blanks and Zeros, etc.
by Tanktalus
in thread Blankety-Blank Blanks and Zeros, etc.
by rir
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |