bc truncate floating point number

Bilal Syed Hussain picture Bilal Syed Hussain · Dec 13, 2013 · Viewed 17.3k times · Source

How do I truncate a floating point number using bc

e.g if I do

echo '4.2-1.3' | bc

which outputs 2.9 how I get it to truncate/use floor to get 2

Answer

timrau picture timrau · Dec 13, 2013

Use / operator.

echo '(4.2-1.3) / 1' | bc