As the title says, when I place an array into http_build_query()
all the float types end up with lost precision. For instance:
$arr = ['test' => 22854.94878205978 ];
print_r($arr); // prints 22854.94878205978
print_r(http_build_query($arr)); // prints 22854.94878206
I'm unsure why. I can't find anything in the PHP docs that would cause this. My main focus is just sending some data via a POST request using cURL via PHP, ie.
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_CUSTOMREQUEST,"POST");
curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($arr));
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
$result = curl_exec($ch);
Since I need the precision, what can I do and why is this happening?