Greetings!
I uses bс to make some calculations in my script. For example:
bc
scale=6
1/2
.500000
For further usage in my script I need "0.500000" insted of ".500000".
Could you help me please to configure bc output number format for my case?
Greetings!
I uses bс to make some calculations in my script. For example:
bc
scale=6
1/2
.500000
For further usage in my script I need "0.500000" insted of ".500000".
Could you help me please to configure bc output number format for my case?
I believe here is modified version of the function:
Just do all your calculations and output in awk:
As an alternative, if you'd prefer to use
bc
and not use AWK alone or with 'bc', Bash'sprintf
supports floating point numbers even though the rest of Bash doesn't.The second line above could instead be:
Which works kind of like
sprintf
would and doesn't create a subshell.Quick and dirty, since
scale
only applies to the decimal digits andbc
does not seem to have asprintf
-like function:In one line:
Can you put the bc usage into a little better context? What are you using the results of bc for?
Given the following in a file called
some_math.bc
on the command line I can do the following to add a zero:
If I only needed the output string to have a zero for formatting purposes, I'd use awk.