bc
    1/2
    0

    5/3
    1

    10/3
    3

When a fraction is entered into bc, the result is truncated to an integer. How can this behavior be avoided, such that the output of a division operation is a real number?

link|improve this question

64% accept rate
feedback

2 Answers

up vote 3 down vote accepted

Try something like scale=2

From the man page:

scale ( expression )

The value of the scale function is the number of digits after the decimal point in the expression.

By default, the scale is 0, so no digits after the decimal are shown.

link|improve this answer
feedback

Use the scale special variable to define decimal places:

scale=4
1/2
.5000
link|improve this answer
Thanks, you both had the right answer, and at essentially the same time. – user001 Jan 12 at 3:30
feedback

Your Answer

 
or
required, but never shown

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