Format number in PHP
I would like to format number with decimal开发者_运维问答 places to format without decimal places, example: 146.5 to 146500000. How can i achieve this in PHP? Thank you.
Multiply by 100000?
Couldn't be that easy.
There are a couple ways to do this:
- Multiply the number by some power of 10
- User
number_format
(docs) to add the zeros, then use str_replace (docs) to remove the decimal point
$formatted_number = preg_replace('/\./', '', sprintf('%06f', $number));
Maybe you meant 1465.00000 then you could use floor($num);
Floating point numbers can be tricksy, be sure to do any multiplication with an extended math library. Check out bcmul()
from the BC Math Library for more info.
精彩评论