Codementor Events

Number to Text Converter

Published Nov 24, 2017

This is a ColdFusion component (cfc) that takes a number as an argument and returns a string representation of that number. It can convert numbers in the range from 1 to 999999999.

Clone or download from GitHub

// Create an object
c = new number2TextConverter();
// Change language 
c.setLanguage('spanish'); 

// Change the currency 
c.setCurrency( 'MX' ); 

// Converting just the number 
result = c.convert( 1999 ); // mil novecientos noventa y nueve 

// Converting the number and adding the currency at the end 
result = c.convert( 1999.50, true ); // mil novecientos novena y nueve 50/100 MX

c.setCurrency( 'pesos' ); 
result = c.convert( 1999.50, true ); //mil novecientos novena y nueve 50/100 pesos

//Language can be changed without creating another object just call setLanguage function 
c.setLanguage('english'); c.setCurrency('USD'); 
result = c.convert( 1999 ); //one thousand nine hundred and ninetynine 
result = c.convert( 1999, true ); //one thousand nine hundred and ninetynine USD 

c.setCurrency( 'dollars' ); 
result = c.convert( 1999.50, true ); //one thousand nine hundred and ninetynine 50/100 dollars
Discover and read more posts from Angel Chrystian Torres Guzmán
get started
post commentsBe the first to share your opinion
Show more replies