Skip to main content
added 324 characters in body
Source Link
user232326
user232326

Try:

echo "scale=20; a=((900/1303) * 928)/600; scale=0; a/1" | bc

However, that's a truncate decimals, a result like 1.9999 will truncate to 1 also.

But that seems to be what you ask for.


How its showing Zero. ...

Because 900/1303 (with zero decimals) becomes 0. The 0 is carried to the end result. Maybe, if you reorder:

$ echo "( 900 * 928 / 1303 ) / 600" | bc
1

... It should show 1 instead

No, it should not, if intermediate divisions are carried out with zero decimals.

Try:

echo "scale=20; a=((900/1303) * 928)/600; scale=0; a/1" | bc

However, that's a truncate decimals, a result like 1.9999 will truncate to 1 also.

But that seems to be what you ask for.

Try:

echo "scale=20; a=((900/1303) * 928)/600; scale=0; a/1" | bc

However, that's a truncate decimals, a result like 1.9999 will truncate to 1 also.

But that seems to be what you ask for.


How its showing Zero. ...

Because 900/1303 (with zero decimals) becomes 0. The 0 is carried to the end result. Maybe, if you reorder:

$ echo "( 900 * 928 / 1303 ) / 600" | bc
1

... It should show 1 instead

No, it should not, if intermediate divisions are carried out with zero decimals.

Source Link
user232326
user232326

Try:

echo "scale=20; a=((900/1303) * 928)/600; scale=0; a/1" | bc

However, that's a truncate decimals, a result like 1.9999 will truncate to 1 also.

But that seems to be what you ask for.