php - Decimal number with only 10 digits for the integer and 6 for the decimals? -
Suppose that the number given to me is 47.50, how can I allow the integer for 10 digits only and for decimal 6 as it is 0000000047.500000 or another example: from 3475.95 it is 0000003475.950000 < p> // Is it ok to use the strappad? How can I use it?
$ amount = straw_pad (3475.95, 10, '0', STR_PAD_LEFT);
is not the most beautiful approach, but hey, we're talking about the script Are you, right?
& lt ;? Php $ value = 47.56; Echo Sprintf ('% s.% S', str_pad (int) $ value, 10, '0', STR_PAD_LEFT), str_pad (substr ($ value- (int) $ value, 2), 6, '0' STR_PAD_RIGHT) ); ? & Gt;
Sorry, could not resist. But obviously, the correct solution was Mark Baker in his comment above: sprintf ("% 016.6f", 3475.95); ...
Comments
Post a Comment