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

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

<p>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. </p>

<p>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.</p>

<p>Best wishes</p>

CC BY-SA 3.0
2013-07-29T19:04:12.100Z
I see [JSON-RPC PHP](http://jsonrpcphp.org/) recommended on the Bitcoin wiki, have you tried swapping that in?
Nick ODell
CC BY-SA 3.0
2013-07-30T08:14:59.020Z
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
CC BY-SA 3.0
2014-04-05T01:58:51.107Z
Just use the string format with "%.8f"
Justin
<json-rpc><php>
Can I force json_encode in PHP to output 8 digits after dot for RPC?
ripazha
# Can I force json_encode in PHP to output 8 digits after dot for RPC?

(Asked by: username_0 on 2013-07-29)

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

**Tags:** json-rpc, php

> **Comments:**
> **username_1**: I see [JSON-RPC PHP](http://jsonrpcphp.org/) recommended on the Bitcoin wiki, have you tried swapping that in?  
> **username_0**: 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.  
> **username_2**: Just use the string format with "%.8f"  

---

## 0 answers

