Skip to content
Advertisement

PHP how to convert number (year) to text ex. 1996 = Ninteen Ninty six, and 2004 = Two thousand four

I have a certificate I want to convert year to text but in the given format

JavaScript

I have a function but it gives me One Thousand Nine Hundred Ninety-Six

JavaScript

I need the return result to be “nineteen hundred ninety-six” please help

Advertisement

Answer

I took the liberty of rewriting and cleaning up your function, adding one crucial part: the conversion from

(a) One Thousand Nine Hundred Ninety Six to (b) Nineteen Hundred Ninety Six.

The function now accepts a optional second argument $year. If set to true, it will return (b), otherwise (a).

numberTowords(1996) will give (a)

numberTowords(1996,true) will give (b)

The comments in de code show what I’ve changed

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement