Hi!
I have a code:
Code:
part1=10; for (( c=1; c<=12; c++ )); do part2=$(calc -p "$part1 / 100 * 25"); part1=$(calc -p "$part1 + $part2"); echo "$part1"; done
I have this problem:
Code:
12.5
15.625
19.53125
24.4140625
30.517578125
38.14697265625
47.6837158203125
59.604644775390625
74.50580596923828125
93.1322574615478515625
69.84919309616088867188
87.31149137020111083985
The problem is that for "calc", this "93.13 + ~23.12" and this "93.13 + 23.12" is not the same and the result is "incorrect".
Is there any way I could get rid of that annoying behavior?
Thank you!
EDIT:
I found a "solution" by doing this:
Code:
part1=10; for (( c=1; c<=12; c++ )); do part2=$(calc -p "$part1 / 100 * 25" | tr -d '~'); part1=$(calc -p "$part1 + $part2" | tr -d '~'); echo "$part1"; done
If you know of a better solution, please let me know.
Thank you!
EDIT:
A better solution was provided by
norobro:
Code:
part1=10; for (( c=1; c<=12; c++ )); do part2=$(calc -p -d "$part1 / 100 * 25"); part1=$(calc -p -d "$part1 + $part2"); echo "$part1"; done
Thank you!