C#實現人民幣金額小寫轉大寫的代碼

來源:互聯網
上載者:User

在做涉及到金額的內容時,通常是需要輸出一個金額的大寫形式,這是中國的傳統哦,嘿嘿,同時也提高安全性。

實現人民幣從小寫到大寫的方法有很多種,今天,我這裡提供一種給大家共用

 

 

一部分代碼展示:
public static string Convert(decimal number){    bool NegativeFlag = false;    decimal RMBNumber;    CheckNumberLimit(number);    RMBNumber = Math.Round(number, 2);    //將?四?舍?五?入?取?位?小?數?    if (RMBNumber == 0)    {        return "零?元?整?";    }    else if (RMBNumber < 0)  //如?果?是?負?數?    {        NegativeFlag = true;        RMBNumber = Math.Abs(RMBNumber);           //取?絕?對?值?    }    else    {        NegativeFlag = false;    }    string buf = "";                           // 存?放?返?回?結?果?    string strDecPart = "";                    // 存?放?小?數?部?分?的?處?理?結?果?    string strIntPart = "";                    // 存?放?整?數?部?分?的?處?理?結?果?    string[] tmp = null;    string strDigital = RMBNumber.ToString();    tmp = strDigital.Split(cDelim, 2); // 將?數?據?分?為?整?數?和?小?數?部?分?    if (RMBNumber >= 1m) // 大?於?時?才?需?要?進?行?整?數?部?分?的?轉?換?    {        strIntPart = ConvertInt(tmp[0]);    }    if (tmp.Length > 1) //分解出了小數    {        strDecPart = ConvertDecimal(tmp[1]);    }    else  //沒有小數肯定是為整    {        strDecPart = "整";    }    if (NegativeFlag == false) //是?否?負?數?    {        buf = strIntPart + strDecPart;    }    else    {        buf = "負" + strIntPart + strDecPart;    }    return buf;}
使用的方法非常簡單:
Console.WriteLine("¥12345.67 對應的大寫金額是 :" + DeltaCat.Net.RMB.Convert(12345.67M));

demo代碼[c#人民幣小寫轉大寫]

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.