I have a float value in my database (the column is DECIMAL 20,16 and it is actually a latitude). When I look into the database it says the value is 51.2205680000000000
When I retrieve the value in php, it is a float and the trailing zero's are gone. It now is 51.220568. Well, no problem, I just add them again... Now I want to convert it to a string as it is a latitude and an API service complains that the latitude is not specific enough, so I add the trailing zero's again because it actually does not matter for this specific case.
$float = 51.220568;
$string = number_format($float, 16);
This returns 51.2205680000000001 with an extra 1 in the end... Same goes for this trick:
$float = 51.220568;
sprintf("%0.16f", $float);
This also returns 51.2205680000000001. I thought I asked to fill it with zero's?
This one is OK:
5.261406
5.2614060000000000
This one has 27 in the end
50.894336
50.8943360000000027
Why is that? And is there an easy way of adding only zero's to the end?