BC—automatic full precision multiplication

You can control the scale that bc outputs with the scale=<#> argument.

$ echo "scale=10; 5.1234 * 5.5678" | bc
28.52606652

$ echo "scale=5; 5.1234 * 5.5678" | bc
28.52606

Using your example:

$ bc <<< 'scale=2; 1.5 * 1.5'
2.25

You can also use the -l switch (thanks to @manatwork) which will initialize the scale to 20 instead of the default of 0. For example:

$ bc -l <<< '1.5 * 1.5'
2.25

$ bc -l <<< '1.52 * 1.52'
2.3104

You can read more about scale in the bc man page.

Tags:

Calculator

Bc