Number To Text Converter

November 24, 2017
Software Architect and Web Developer
Guide 3 posts
Followers: 0 people
0

Number To Text Converter

Software Architect and Web Developer
Guide 3 posts
Followers: 0 people
November 24, 2017
number2TextConverter.cfc

This is a component 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
Comments (0)
Add your comment