Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Converting number to string representation
Message
From
29/04/2009 03:11:08
 
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01396542
Message ID:
01396868
Views:
60
>BTW - did you see this code in Sylvains link: (and the sample result)
>    static string wordify(decimal v)
>    {
>        if (v == 0) return "zero";
>        var units = "|one|two|three|four|five|six|seven|eight|nine".Split('|');
>        var teens = "|eleven|twelve|thir#|four#|fif#|six#|seven#|eigh#|nine#".Replace("#", "teen").Split('|');
>        var tens = "|ten|twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety".Split('|');
>        var thou = "|thousand|m#|b#|tr#|quadr#|quint#|sex#|sept#|oct#".Replace("#", "illion").Split('|');
>        var g = (v < 0) ? "minus " : "";
>        var w = "";
>        var p = 0;
>        v = Math.Abs(v);
>        while (v > 0)
>        {
>            int b = (int)(v % 1000);
>            if (b > 0)
>            {
>                var h = (b / 100);
>                var t = (b - h * 100) / 10;
>                var u = (b - h * 100 - t * 10);
>                var s = ((h > 0) ? units[h] + " hundred" + ((t > 0 | u > 0) ? " and " : "") : "")
>                      + ((t > 0) ? (t == 1 && u > 0) ? teens[u] : tens[t] + ((u > 0) ? "-" : "") : "")
>                      + ((t != 1) ? units[u] : "");
>                s = (((v > 1000) && (h == 0) && (p == 0)) ? " and " : (v > 1000) ? ", " : "") + s;
>                w = s + " " + thou[p] + w;
>            }
>            v = v / 1000;
>            p++;
>        }
>        return g + w;
>    }

Yes, I have come across that while I was looking at one of the links
Gregory
Previous
Reply
Map
View

Click here to load this message in the networking platform