Can I use python float with precision of (float32) ? Because it will be serialized from primitive python.float(32) and will be deserialized to primitive java.float. Any libraries are not considered. ex) numpy.float32
Asked
Active
Viewed 562 times
0
-
Have you tried it? You will have much better chances of getting an answer if you provide an [MCVE](https://stackoverflow.com/help/mcve). – Craig Apr 11 '17 at 01:46
1 Answers
0
Python floats are 64-bit (double
in C/Java). However you can serialize/deserialize these to 32-bit floats (float
in C/Java) using the struct
module with the "f"
format:
>>> import struct
>>> struct.pack("f", 0.1)
'\xcd\xcc\xcc='

Simon Byrne
- 7,694
- 1
- 26
- 50