Multiplying an int with a float will result in an incorrect value using g++ / visual studio
It will always work fine when using double instead of float.
The calculation is also very simple - 1000 * 0.01 - should be 10 - but its 9.
Sample Program
#include <iostream>
#include <stdio.h>
typedef unsigned long long int64;
typedef unsigned int int32;
int main()
{
int64 test = 1000 * 0.01f;
printf("Test %u\n",test); // Prints 10
int64 test2 = 1000;
test2 = test2 * 0.01f;
printf("Test2 %u\n",test2); // Prints 9
int32 test3 = 1000;
test3 = test3 * 0.01f;
printf("Test3 %i\n",test3); // Prints 9
int64 test4 = 1000;
test4 = test4 * 0.01;
printf("Test4 %u\n",test4); // Prints 10
int32 test5 = 1000;
test5 = test5 * 0.01;
printf("Test5 %i\n",test5); // Prints 10
}
output
Test 10
Test2 9
Test3 9
Test4 10
Test5 10
Compiled on Wheezy 32bit using g++ main.cpp -o main
EDIT: This was just an oversimplification!!!
Basically i do NOT use 0.01f
What i do is this convert one unit to another, e.g. one of my units is 1:100 to another unit. Another one is 1:10 or 1:1000.
So i basically calculate unit1/unit2 to have the correct multiplier if i want to sum 2 different units.
In that case it was unit1 = 1000 unit2 = 10
so 10/1000 = 0.01 * 1000 = 10
So when i want to convert 1000 pieces of unit1 into unit2 it should result in 10 because basically unit1 is 1000 of base, and unit2 is 10 base.