Вопрос

I am trying to scale my number calculation to one decimal place (with all applicable rounding) using the bc command in linux. This is my test expression:

echo "scale 1; 90 - 70.333" | bc

However, I end up with 3 decimal places:

19.667 is the result.

Any idea how to use bc properly to do this?

Это было полезно?

Решение

Instead of using

echo "scale 1; 90 - 70.333" | bc

Try to use

echo "scale 1; 90 - 70.333/1" | bc

That might do the trick.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top