Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

It looks like bc doesn't support float operations, when I do echo 1/8 | bc it get me a zero.

I checked bc (1), but it doesn't even mention float, so I wonder if it's supported?

share|improve this question
echo "scale=4; 1/8" | bc – LiuYan 刘研 Mar 4 '13 at 2:20
This question and in particular the accepted answer might be interesting to you. – Emanuel Berg Mar 6 '13 at 1:21
up vote 22 down vote accepted

bc doesn't do floating point but it does do fixed precision decimal numbers. The -l flag Hauke mentions loads a math library for eg. trig functions but it also means

[...] the default scale is 20

scale is one of a number of "special variables" mentioned in the man page. You can set it:


Anytime you want (whether -l was used or not). It refers to the number of significant digits used in a decimal. In other words, subsequent solutions will be rounded to that number of digits after the decimal scale (== fixed precision).

The default scale sans -l is 0, meaning rounded to whole numbers.

share|improve this answer

man page says:

If bc is invoked with the -l option, a math library is preloaded [...]

The comprehensibility of that could be improved, indeed...

share|improve this answer
Report it upstream as a bug... – vonbrand Mar 4 '13 at 3:18

Your Answer


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.