How can I convert an integer into its verbal representation?

后端 未结 14 2175
走了就别回头了
走了就别回头了 2020-11-22 15:23

Is there a library or a class/function that I can use to convert an integer to it\'s verbal representation?

Example input:

4,567,788`

14条回答
  •  心在旅途
    2020-11-22 16:20

    if you use the code found in: converting numbers in to words C# and you need it for decimal numbers, here is how to do it:

    public string DecimalToWords(decimal number)
    {
        if (number == 0)
            return "zero";
    
        if (number < 0)
            return "minus " + DecimalToWords(Math.Abs(number));
    
        string words = "";
    
        int intPortion = (int)number;
        decimal fraction = (number - intPortion)*100;
        int decPortion = (int)fraction;
    
        words = NumericToWords(intPortion);
        if (decPortion > 0)
        {
            words += " and ";
            words += NumericToWords(decPortion);
        }
        return words;
    }
    

提交回复
热议问题