Results 1 to 1 of 1

Thread: [.NET 3.5+] NumberConverter - Convert Numbers Into Their Word Equivalent

  1. #1

    Thread Starter
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    [.NET 3.5+] NumberConverter - Convert Numbers Into Their Word Equivalent

    I recently made a cheque printing application for a business I was working with and I had to convert a number into it's written form. I did some searching and found some stuff, but I didn't like how they were implemented or written. Not to mention the spelling mistakes. Anyway, the attached class can internally handle up to 63 digits which is a hundred Vigintillion, anything past 63 digits requires a delegate where you supply the name of the larger number.

    Quick example:
    Code:
    Dim value = "109284021804812094102984012804812048102840912840812048127250412785"
    
    Console.WriteLine(NumberConverter.Convert(value))
    Output:
    Code:
    One Hundred Nine Vigintillion Two Hundred Eighty Four Novemdecillion
    Twenty One Octodecillion Eight Hundred Four Septendecillion Eight Hundred
    Twelve Sexdecillion Ninety Four Quindecillion One Hundred Two
    Quattuordecillion Nine Hundred Eighty Four Tredecillion Twelve Duodecillion
    Eight Hundred Four Undecillion Eight Hundred Twelve Decillion Forty Eight
    Nonillion One Hundred Two Octillion Eight Hundred Forty Septillion Nine
    Hundred Twelve Sextillion Eight Hundred Forty Quintillion Eight Hundred
    Twelve Quadrillion Forty Eight Trillion One Hundred Twenty Seven Billion Two
    Hundred Fifty Million Four Hundred Twelve Thousand Seven Hundred Eighty Five
    If you want more than 63 digits:
    Code:
    Dim value = "1092840218048120941029840128048120481028409128408120481272504127851244654511"
    
    Console.WriteLine(NumberConverter.Convert(value, AddressOf Me.OnQueryLargeNumberText))
    
    Private Function OnQueryLargeNumberText(index As Integer) As String
        Select Case index * 3
            Case 66
                Return "Huge Tons"
            Case 69
                Return "Crap Tons"
            Case 72
                Return "Way Too Muchs"
            Case Else
                Return "I Give Up's"
        End Select
    End Function
    
    Output:
    Code:
    One I Give Up's Ninety Two Way Too Muchs Eight Hundred Forty Crap Tons
    Two Hundred Eighteen Huge Tons Forty Eight Vigintillion One Hundred
    Twenty Novemdecillion Nine Hundred Forty One Octodecillion Twenty Nine
    Septendecillion Eight Hundred Forty Sexdecillion One Hundred Twenty Eight
    Quindecillion Forty Eight Quattuordecillion One Hundred Twenty Tredecillion
    Four Hundred Eighty One Duodecillion Twenty Eight Undecillion Four Hundred
    Nine Decillion One Hundred Twenty Eight Nonillion Four Hundred Eight Octillion
    One Hundred Twenty Septillion Four Hundred Eighty One Sextillion Two
    Hundred Seventy Two Quintillion Five Hundred Four Quadrillion One Hundred
    Twenty Seven Trillion Eight Hundred Fifty One Billion Two Hundred Forty Four
    Million Six Hundred Fifty Four Thousand Five Hundred Eleven
    Attached Files Attached Files
    Last edited by ForumAccount; Jan 9th, 2012 at 06:28 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width