Converting 'small' numbers to English is not to troublesome. But if you handle BCMath Arbitrary Precision numbers then it can be.
Using code from:
http://marc.info/?l=php-general&m=99928281523866&w=2
The maximum number seems to be:
two billion one hundred forty seven million four hundred eighty three thousand six hundred forty seven
Anyone know a function to convert numbers bigger than that?
For numbers larger than
PHP_MAX_INT
, you'll have to either write the function on rely on an external service, such as WolframAlpha.The only functionality PHP offers for this is Intl's
NumberFormatter
.NumberFormatter::format
accepts floats, but this means it can only handle integers up to 2^63-1 in 64-bit long architectures or 52-bit numbers in 32-bit ones.You have to write your own function, I suggest to use numbers as a string, let a substract like this:
example:
will output
I wrote the vpi2english function to handle integers as large as 10^306 - 1. It is part of my VPI toolbox.