I need to convert say $89.50 to Eighty-Nine Dollars and Fifty Cents using PHP. Is there a function I’m missing somewhere?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here’s a start for you. It’s a recursive function I wrote a while back (part of solving a Project Euler problem 17) that converts numbers to letters… It can handle some pretty big numbers 😉
All you need to do is add the dollars and cents components and modify according to need. So basically you’d have to call the function once for the dollar amount and once for the cents component. I don’t think there’s a native PHP funciton for this. You’d have to use a library (like Pear) function.
(You can see the function in action):