The example of the C #. NET implementation of the currency conversions described in this article mainly uses String.Format and CultureInfo to convert. Share it for everyone's reference. Here's how:
The main implementation code is as follows:
<summary>///Enter float format number, convert it to currency expression///</summary>//<param name= "ftype" > Currency expression type: 0 = currency expression with ¥ ; 1 = currency expression without ¥; other = currency expression with ¥ </param>//<param name= "Fmoney" > incoming int digits </param>//<returns> Returns the currency representation of the conversion </returns> public string Rmoney (int ftype, double fmoney) {string _rmoney; try {switch (ftype) {case 0: _rmoney = string. Format ("{0:c2}", Fmoney); Break Case 1: _rmoney = string. Format ("{0:n2}", Fmoney); Break Default: _rmoney = String. Format ("{0:c2}", Fmoney); Break }} catch {_rmoney = ""; } return _rmoney; }///<summary>///Enter float format number, convert it to currency expression///</summary>//<param name= "ftype" > Currency expression type: 0 = RMB; 1 = HKD ; 2= dollar bill; 3 = GBP; 4 = no currency; others = no currency expression </param>//<param name= "Fmoney" > incoming int digits </param>//<returns > returns the converted currency representation </returns> public static string convertcurrency (decimal fmoney) {CultureInfo cul = null; int ftype=4; String _rmoney=string. Empty; try {sWitch (ftype) {case 0:cul = new CultureInfo ("ZH-CN");//Mainland China _rmoney = Fmoney. ToString ("C", cul); Break Case 1:cul = new CultureInfo ("ZH-HK");//HONG Kong _rmoney = Fmoney. ToString ("C", cul); Break Case 2:cul = new CultureInfo ("en-us");//USA _rmoney = Fmoney. ToString ("C", cul); Break Case 3:cul = new CultureInfo ("EN-GB");//UK _rmoney = Fmoney. ToString ("C", cul); Break Case 4: _rmoney = string. Format ("{0:n}", Fmoney);//no currency symbol break; Default: _rmoney = String. Format ("{0:n}", Fmoney); Break }} catch {_rmoney = ""; } return _rmoney; }
Hopefully this article will help you with your C # program design