After a quick look at the source (see bc_out_num() , line 1461), I see no obvious way to make the leading 0 print if the integer part is 0 . If I did not miss anything, this behavior does not depend on a parameter that can be changed using the command line flag.
Short answer: no, I donβt think there is a way to make bc print numbers the way you want.
I don't see anything wrong with using sed if you still want to use bc . The following does not look so terrible, IMHO:
[me@home]$ echo "0.1 + 0.1" | bc | sed 's/^\./0./' 0.2
If you really want to avoid sed , eljunior's and choroba's suggestions are pretty neat, but they require a cost- specific setup to avoid trailing zeros. This may or may not be a problem for you.
Shawn Chin Dec 06 '11 at 16:19 2011-12-06 16:19
source share