I tried the following code on mac, the output is kind of strange to me.
float a = 2.225;
float b = 123.235;
printf("round: %.2f %.2f \n", a, b);
printf("round: %.2f %.2f \n", 2.225, 123.235);
output:
round: 2.22 123.24
round: 2.23 123.23
g++ --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
What are the rounding rules in printing? How I can get same printing result in these two situations? Many thanks.