I have a Client program by tcp connection that send data to a server.
In client I need send a normalized decimal number to server for normalization I Multiplier decimal number to 100,000 then send it to server but I get wrong number in server.
for example.
double price;
I set it from Gui to 74.40
cout<<price; ---> 74.40
and when I serial my object I send
#define Normal 100000
int tmp = price*Normal;
oDest<<tmp;
In wireshrk I see that client sent 7439999.
why this happened? how I can pervent this problem?
Don’t store anything as a floating point value. Use a rational number instead, or use a fixed point value. Floating point values (like
double) basically “cheat” in order to fix a large range of possible values into a reasonable chunk of memory, and they have to make compromises in order to do so.If you are storing a financial value, consider storing pennies or cents or whatever is the smallest denomination.