1

Possible Duplicate:
Is there an easy way to convert a number to a word in PHP?

Recently I needed to change a number to string just like below in php

$str=100;

{ Here will be the code which will return One Hundred not 100}

so $str=150 then will return one hundred fifty

How can I do it. How can I change the number to text in php (NB: number will be random) please help me

Community
  • 1
  • 1
Haren Sarma
  • 2,267
  • 6
  • 43
  • 72
  • 3
    Have you tried anything or do you just want someone to code it for you? – millimoose Feb 04 '12 at 22:03
  • Hhh, homework? Anyway: `$expontents = array( 1000000000 => 'billion', 1000000 = 'million', 1000 => 'thousand', 100 => 'hundred'); $decades = array( 10 => 'ten', 20 => 'twenty'), $numbers = array( 'zero', 'one', 'two'), $specials => array( 11 => 'eleven')` and `%<>+-*/, floor` is way to go :) – Vyktor Feb 04 '12 at 22:06

3 Answers3

1

Use Numbers_Words Pear package.

Example.

 require('Numbers/Words.php');
 $number = 150;
 $nw = new Numbers_Words();
 $numw = $nw->toWords($number);

 echo $numw; //one hundred fifty
Shiplu Mokaddim
  • 56,364
  • 17
  • 141
  • 187
  • Has anyone tried numbers greater than 999,999,999 (a billion and above)? 1,000,000,000 says "One Thousand Million" !? – burntblark Nov 09 '19 at 12:37
0

The solution to this problem has been suggested in the comments of the php documentation at the following location: http://www.php.net/manual/en/function.number-format.php#97020

Hope that helps

ralfe
  • 1,412
  • 2
  • 15
  • 25
0

There is a PEAR package that will do this for you ...

http://pear.php.net/package-info.php?package=Numbers_Words

Christopher Hackett
  • 6,042
  • 2
  • 31
  • 41