We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

your expected result would be with 3 decimal points. You should note that there is there is no rounding off done by bc.

Now in bash you can use the printf function to do the rounding off that you require. Use scale = 4 and then use printf to round off to 3 decimal points using "%.3f"

The basic arithmetic operations are very important for solving any mathematical problem build your own engagement ring online. It is the basics of Mathematics. Addition, subtraction, multiplication, and division is a basic arithmetic operation. Also, a more advanced operation is there. it helps to handle many of the difficult problems.

That's because "-l" sets the scale to 20 as a side effect of loading its math library. The printf does not fix the lack of scale in plain bc solutions.

## Arithmetic Operations

You are viewing a single comment's thread. Return to all comments →

When you use

your expected result would be with

`3`

decimal points. You should note that there is there is norounding offdone bybc.Now in bash you can use the

printffunction to do the rounding off that you require. Use`scale = 4`

and then useprintfto round off to 3 decimal points using`"%.3f"`

then why not only using printf?

`printf "%.3f"`

`e"|bc)`

just avoid the

`scale`

.`printf "%.3f"`

will be sufficientAvoiding

`scale`

defaults to`scale=0`

, so that won't work.then whats the use of setting precision in printf

It rounds the number got from bc to 3 decimal points. Bc does no rounding.

As @bewuethr mentions avoiding scale won't work, but if you used bc -l it would as this defaults to scale of 20.

thanks :)

printf "%.3f\n" exp | bc -l)

There is a $ before the parenthesis that is being interpreted in the comment

Why do you need the "$" before the echo part?

above command not able to write in STDOUT

read num echo $num | bc -l | xargs printf "%.*f\n" 3

The basic arithmetic operations are very important for solving any mathematical problem build your own engagement ring online. It is the basics of Mathematics. Addition, subtraction, multiplication, and division is a basic arithmetic operation. Also, a more advanced operation is there. it helps to handle many of the difficult problems.

You dont need to worry about the scale if you use printf

That's because "-l" sets the scale to 20 as a side effect of loading its math library. The printf does not fix the lack of scale in plain bc solutions.