after reading bitcoin wiki "Proper money handling" I supposed that there shouldn't be any precision problems.

However, sending/moving for instance 16999999.99999999 sends/moves 17000000. I figured out where the problem is:
- PHP stores float value with sufficient precision. I can printf it with 8 correct digits after dot.
- json-rpc php library copies that float into "params" array, and again, precision is fine.
- Unfortunately, string produced by json_encode() used in json-rpc library contains "rounded" value, so there is a problem.

So, can I force json_encode() to output 8 digits (or more)? Or do I have to write my own, which isn't very complicated, but will be rather slower than standard function.

Please note those topics about problems with floats in PHP and Python on bitcointalk, so it is not my fault. One of the results of this issue is genjix branch of bitcoin, that sends amounts as strings.

Best wishes

  • I see JSON-RPC PHP recommended on the Bitcoin wiki, have you tried swapping that in? – Nick ODell Jul 29 '13 at 19:04
  • Well, I'm using that library, but I was trying to use others, too. But it is problem with json_encode(), which is PHP function, not a library function. This function is used in nearly all libraries, so it doesn't help. – ripazha Jul 30 '13 at 8:14
  • Just use the string format with "%.8f" – Justin Apr 5 '14 at 1:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.