Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a big number:

2923174917395723957

that would be:

2,923*10^18

are there any parameters in bc that will give this OUTPUT?
e.g.:

$ echo '2923174917395723956 + 1' | bc
2,923*10^18
$ 

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

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

Try the printf command:

$ printf "%e\n" 2923174917395723957
2.923175e+18

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

$ printf "%.3e\n" 2923174917395723957
2.923e+18

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'
2.923e+18
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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