I'm pretty confused about these 4 statements ( or I'm just a blockhead in understanding the evaluation order / precedence of operators and parentheses ).
The first and third statement print a simple arithmetic opertation (using differently placed parentheses) in a float value interpreted sprintf instruction. That is ok.
But why does the second and fourth statement print different rounded values? I have no clue and don't know how to find out.
Please, could someone advise?
perl -e 'print sprintf( "%f", 66.5 * ( ( 100 + 19 ) / 100 ) ), "\n +79.135000"' perl -e 'print sprintf( "%.2f", 66.5 * ( ( 100 + 19 ) / 100 ) ), " < +-- wrong, expected 79.14\n"' perl -e 'print sprintf( "%f", 66.5 * ( 100 + 19 ) / 100 ), "\n +79.135000"' perl -e 'print sprintf( "%.2f", 66.5 * ( 100 + 19 ) / 100 ), " < +-- ok = 79.14\n"'
In reply to strange sprintf behavior? by oseeliger
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |