I read price from user input. When i multiply the input with int like this
T=
\"$((PRICE*QTY))\"|bc
; gives line 272: 12.
First, trying to do floating-point arithmetic with bc(1)
without using the -l
flag is bound to give you some funny answers:
sarnold@haig:~$ bc -q
3.5 * 3.5
12.2
sarnold@haig:~$ bc -q -l
3.5 * 3.5
12.25
Second, the $((...))
is an attempt to do arithmetic in your shell; neither my bash
nor dash
can handle floating point numbers.
If you want to do the arithmetic in your shell, note printf(1)
as well as (probably) your shell's built-in printf
function. If you want to do the arithmetic in bc, note the special variable scale
.