Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Converting number to string representation
Message
De
27/04/2009 22:22:44
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
 
 
À
27/04/2009 20:25:52
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01396542
Message ID:
01396598
Vues:
51
>>See if this is it http://www.devx.com/vb2themax/Tip/19053
>
>I do not know if you tried that but that doesn't work at all. When I first look at it, I said: "Wow, this is the most amazing simplified version of such logic I have ever seen.". But, it requires a lot of adjustments.
>
>I have tried to adjust it a little bit and so far, I have this:
>
>
>    Private Function NumberToWords(ByVal tnValue As Long, _
>     Optional ByVal BlankIfZero As Boolean = False) As String
>        Dim lcNumberToWords As String = ""
>
>        Select Case tnValue
>
>            Case 0
>                lcNumberToWords = IIf(BlankIfZero, "", "Zero")
>
>            Case 1 To 19
>                lcNumberToWords = Choose(tnValue, "One", "Two", "Three", "Four", _
>                 "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", _
>                 "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", _
>                 "Seventeen", "Eighteen", "Nineteen")
>
>            Case 20 To 99
>                lcNumberToWords = Choose(tnValue \ 10 - 1, "Twenty", "Thirty", _
>                 "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", _
>                 "Ninety") & NumberToWords(tnValue Mod 10, True)
>
>            Case 100 To 999
>                lcNumberToWords = NumberToWords(tnValue \ 100) & "Hundred" & IIf _
>                 (tnValue >= 200, "s", "") & NumberToWords(tnValue Mod 100, True)
>
>            Case 1000 To 999999
>                lcNumberToWords = NumberToWords(tnValue \ 1000) & "Thousand" & IIf _
>                 (tnValue >= 2000, "s", "") & NumberToWords(tnValue Mod 1000, True)
>
>            Case 1000000 To 999999999
>                lcNumberToWords = NumberToWords(tnValue \ 1000000) & "Million" & IIf _
>                 (tnValue >= 2000000, "s", "") & NumberToWords(tnValue Mod 1000000, True)
>
>            Case Is >= 1000000000
>                lcNumberToWords = NumberToWords(tnValue \ 1000000000) & "Billion" & _
>                 IIf(tnValue >= 2000000000, "s", "") & NumberToWords(tnValue Mod _
>                 1000000000, True)
>        End Select
>
>        Return lcNumberToWords
>    End Function
>
>
>But, this doesn't take care of the spacing issue, the casing and the decimals. If someone wants to proceed on enhancing that, you are welcome.

Michel, the code snipped I posted works, as I tested it out today. However, it looks like you need to do decimals?
Very fitting: http://xkcd.com/386/
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform