Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using negative exponents with bc in Bash

Tags:

bash

exponent

bc

I'm having a difficulty with using negative exponents in the program bc in Bash. If I execute echo "2*1.86929*10^05" | bc, I get a result of 373858.00000 while if I execute echo "2*1.86929*10^-05" | bc, I get a result only of 0. How can I get better accuracy when using negative exponents?

like image 650
d3pd Avatar asked Jan 14 '23 02:01

d3pd


1 Answers

By default, the output of bc is rounded to an integer. To keep the decimal part of the result, use bc -l, like this:

$ echo "2*1.86929*10^-05" | bc -l
.00003738580000000000
like image 65
user000001 Avatar answered Jan 21 '23 07:01

user000001