I am attempting to use PHP's
printf function to print out a user's storage capacity. The full formula looks something like this:
echo printf("%.02f", ($size/(1024*1024))) . " GB";
$size == (10 * 1024 * 1024), this should print out
But it doesn't. It prints
10.04 GB. Furthermore,
echo printf("%.02f", 10)
What?! In giving it an integer to convert to a float, it converts 10 to 10.00000009.
How can this be remedied? Obviously, one solution would be to print it out as an integer, but the value will not always be an integer; it may be 5.57 GB, in which case the accuracy of this script is very important.
echo printf("%d", 10)
Something is very wrong here.