java - transfer float across network via socket -


we have tcp/ip socket software including java client , c++ server. data across socket contains numbers, int, float, , char array. precision of these floats four digits after point. recently, started use either char array represent float in data structure/protocol or int represent float (float int time 10000 , divide 10000 on receiver side) because of precision.

i told difficulty keep precision if use float inside data structure/protocol directly. sender hard put float socket , receiver hard receive/convert exact float number.

i not convinced. reading wiki again. seems single-precision float can provide 6-9 precision:

this gives 6 9 significant decimal digits precision (if decimal string @ 6 significant decimal converted ieee 754 single precision , converted same number of significant decimal, final string should match original; , if ieee 754 single precision converted decimal string @ least 9 significant decimal , converted single, final number must match original [3]).

what's practice transfer float across internet if required precision 4 or 6? how more that? double!?. how banks handle bigger floating point numbers?

have looked @ google protocol buffers? https://code.google.com/p/protobuf/

basically, use protobuf serialize float string, send string on network, , use protobuf on other side turn float. while you're @ can send rest of message string protobuf enforce structure/consistency in data send.

additionally, encoded message language independent, language has protocol buffer library (google provides c++, python, , java implementations, , there countless third-party implementations other languages) can read/parse/use message.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -