Skip to main content
fixed answer
Source Link

Thanks to @Stéphane Chazelas for pointing out my misuse of variable


Just a little fixcompletion of @user2323 's answer:

> printf '%.2f\n' "$((multiplied*100*100outsideLines*100*100/totalLines))e-2" > 42.85 

Since 'e-2' is appended at the end, it should add one more 100 at the beginning. "$((multiplied*100outsideLines*100/totalLines))" will only get the integer part of percentage:

> printf '%.2f\n' "$((multiplied*100outsideLines*100/totalLines))" > 42 

, and "$((multiplied*100outsideLines*100/totalLines))e-2" get a float number with two decimals, but not the percentage:

> printf '%.2f\n' "$((multiplied*100outsideLines*100/totalLines))e-2" > 0.42 

Just a little fix of @user2323 's answer:

> printf '%.2f\n' "$((multiplied*100*100/totalLines))e-2" > 42.85 

Since 'e-2' is appended at the end, it should add one more 100 at the beginning. "$((multiplied*100/totalLines))" will only get the integer part of percentage:

> printf '%.2f\n' "$((multiplied*100/totalLines))" > 42 

, and "$((multiplied*100/totalLines))e-2" get a float number with two decimals, but not the percentage:

> printf '%.2f\n' "$((multiplied*100/totalLines))e-2" > 0.42 

Thanks to @Stéphane Chazelas for pointing out my misuse of variable


Just a little completion of @user2323 's answer:

> printf '%.2f\n' "$((outsideLines*100*100/totalLines))e-2" > 42.85 

Since 'e-2' is appended at the end, it should add one more 100 at the beginning. "$((outsideLines*100/totalLines))" will only get the integer part of percentage:

> printf '%.2f\n' "$((outsideLines*100/totalLines))" > 42 

, and "$((outsideLines*100/totalLines))e-2" get a float number with two decimals, but not the percentage:

> printf '%.2f\n' "$((outsideLines*100/totalLines))e-2" > 0.42 
Source Link

Just a little fix of @user2323 's answer:

> printf '%.2f\n' "$((multiplied*100*100/totalLines))e-2" > 42.85 

Since 'e-2' is appended at the end, it should add one more 100 at the beginning. "$((multiplied*100/totalLines))" will only get the integer part of percentage:

> printf '%.2f\n' "$((multiplied*100/totalLines))" > 42 

, and "$((multiplied*100/totalLines))e-2" get a float number with two decimals, but not the percentage:

> printf '%.2f\n' "$((multiplied*100/totalLines))e-2" > 0.42