Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Converting number to string representation
Message
De
29/04/2009 02:54:36
 
 
À
28/04/2009 08:39:40
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01396542
Message ID:
01396865
Vues:
57
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;
    }
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform