Convert Numbers to Text using ColdFusion and ICU4J

(This is a repost from my abandoned tumblr blog; dated 2016-11-17)

A client requested that we spell out numbers on their website in order to clarify some financial totals.  I initially planned on using the ColdFusion NumberAsString UDF from 2002. Afte…


This content originally appeared on DEV Community and was authored by James Moberg

(This is a repost from my abandoned tumblr blog; dated 2016-11-17)

A client requested that we spell out numbers on their website in order to clarify some financial totals.  I initially planned on using the ColdFusion NumberAsString UDF from 2002. After reviewing the results, I thought it was worth a unit test comparison to review the results against ICU4J (java).

In the end, I decided to use ICU4J because:

  • ICU4J converts text using 180+ locales. Numbers are translated to each language (Chinese, Thai, French, Spanish, etc)
  • UDF adds title case capitalization to all number strings. (if needed, you can do this separately.)
  • UDF doesn't support negative values and will throw a CF error.
  • UDF doesn't use hyphenized numbers ("Forty Three" versus "forty-three")
  • UDF uses "cardinal-verbose" format w/o hyphened numbers (Adds the word "and" where commas should be.)
  • UDF decimal places are treated as positive-type number words (instead of using "point four three" for ".43")
123 = "one hundred twenty-three"
100001 = "one hundred thousand one"
9 = "nine"
64578.25 = "sixty-four thousand five hundred seventy-eight point two five"
0.333 = "zero point three three three"

Here's the CFML source code:
https://gist.github.com/JamoCA/cd343524e417f382d5c706954e52dfaf


This content originally appeared on DEV Community and was authored by James Moberg


Print Share Comment Cite Upload Translate Updates
APA

James Moberg | Sciencx (2024-07-25T23:34:22+00:00) Convert Numbers to Text using ColdFusion and ICU4J. Retrieved from https://www.scien.cx/2024/07/25/convert-numbers-to-text-using-coldfusion-and-icu4j/

MLA
" » Convert Numbers to Text using ColdFusion and ICU4J." James Moberg | Sciencx - Thursday July 25, 2024, https://www.scien.cx/2024/07/25/convert-numbers-to-text-using-coldfusion-and-icu4j/
HARVARD
James Moberg | Sciencx Thursday July 25, 2024 » Convert Numbers to Text using ColdFusion and ICU4J., viewed ,<https://www.scien.cx/2024/07/25/convert-numbers-to-text-using-coldfusion-and-icu4j/>
VANCOUVER
James Moberg | Sciencx - » Convert Numbers to Text using ColdFusion and ICU4J. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/07/25/convert-numbers-to-text-using-coldfusion-and-icu4j/
CHICAGO
" » Convert Numbers to Text using ColdFusion and ICU4J." James Moberg | Sciencx - Accessed . https://www.scien.cx/2024/07/25/convert-numbers-to-text-using-coldfusion-and-icu4j/
IEEE
" » Convert Numbers to Text using ColdFusion and ICU4J." James Moberg | Sciencx [Online]. Available: https://www.scien.cx/2024/07/25/convert-numbers-to-text-using-coldfusion-and-icu4j/. [Accessed: ]
rf:citation
» Convert Numbers to Text using ColdFusion and ICU4J | James Moberg | Sciencx | https://www.scien.cx/2024/07/25/convert-numbers-to-text-using-coldfusion-and-icu4j/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.