Representing a number in spelled out format

1,740 pts.
Tags:
Desktops
Management
Microsoft Windows
OS
Security
Servers
SQL Server
Does anyone know of an add-in to Visual Basic with a function that will format a number in its spelled out format? Example 1,101 = one thousand one hundred one. Or, does anyone know the location of downloadable code that can be incorporated into a VB project? Thanks
ASKED: May 14, 2007  3:34 PM
UPDATED: May 14, 2007  4:42 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

This is easy enough to write. Here’s the pseudocode:

Top level:
…If the number is zero
……Return “zero”
…Call level 2 with trunc(number/1000000000000), “trillion”
…Call level 2 with mod(trunc(number/1000000000),1000), “billion”
…Call level 2 with mod(trunc(number/1000000),1000), “million”
…Call level 2 with mod(trunc(number/1000),1000), “thousand”
…Call level 2 with mod(number,1000), “”

Level 2:
…localNumber = number
…If localNumber>=100
……Call level 2 with trunc(localNumber/100), “hundred”
……localNumber = mod(localNumber,100)
…If localNumber>19
……Output from an array of “twenty”, “thirty”, …, “ninety” indexed by trunc(localNumber/10)-1
……localNumber = mod(localNumber,10)
…If localNumber>0
……Output from an array of “one”, “two”, …, “nineteen” indexed by localNumber
…If number>0
……Output the word passed as the second argument

If you need dollars and cents, Add this over-level:
…dollars = trunc(number)
…cents = mod(number, 1) * 100
…if dollars>0
……Output the english of dollars
……Output “dollars”
……If cents>0
………Output “and”
………Output the english of cents
………Output “cents”
…else
……if cents>0
………Output the english of cents
………Output “cents”
……else
………Output “zero”

Note that in other languages, the rules are different. For instance, in Spanish, >19 becomes >15, and you need to add “ten” to the first list. In Korean, you need a line in the first level for each tens place, using “chip”, “ma”, and all of those words.

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following