Hello I have this code in C#:
float n = 2.99499989f;
MessageBox.Show("n = " + n.ToString("f2", CultureInfo.InvariantCulture));
And this code in C++:
float n = 2.99499989f;
printf("n = %.2f", n);
First one outputs 3.00.
Second one outputs 2.99.
I have no clue why this is happening.
Update:
I also tried Objective-C NSLog and the output is 2.99.
I needed to fix it fast so I used following method:
float n = 2.99499989f;
float round = (float)Math.Round(n, 2);
MessageBox.Show("round = " + round.ToString(CultureInfo.InvariantCulture));
This code shows 2.99, but computes round in double precision. I can't find Math.RoundF.