I have a big number:


that would be:


are there any parameters in bc that will give this OUTPUT?

$ echo '2923174917395723956 + 1' | bc

Or something similar...the point is that it must have a short look
Thank you!


Try the printf command:

$ printf "%e\n" 2923174917395723957

In your locale, it should use , instead of ., of course. You can also control the format more precisely such as:

$ printf "%.3e\n" 2923174917395723957

Some shells like bash have a built-in called printf which may be different from any printf command that comes with the system, but, in general, you shouldn't notice any difference with simple commands like above. You can also use printf from Perl which will be pretty consistent.

$ perl -e 'printf "%.3e\n", 2923174917395723957'

In bc numbers are represented as decimals, (in fact in base 100, one digit per byte), not the way processors do. Numbers are output as there are stored in bc internal registry. The print function as no option to print numbers with exponent. But in bc everything is possible. You can make your own function to format numbers output. You can store your own functions in a file and add the file path to the variable BC_ENV_ARGS, then functions will be available each time you invoke bc.

Check http://phodd.net/gnu-bc/code/output_formatting.bc for printfe function...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.