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 number </param>///<returns> Returns the currency representation of the transformation </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>///input 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 number </param>///<returns> Returns the currency representation of the transformation </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;}
I hope this article is helpful to everyone's C # program design
In addition to the Declaration,
Running GuestArticles are original, reproduced please link to the form of the address of this article
C #. NET Implements currency conversion example
This address: http://www.paobuke.com/develop/c-develop/pbk23580.html
Related content sqltransaction―― transactions in C # The analysis of the usage of Mutex objects in C # The difference between dynamic and Var and dynamic use C # effectively prevents multiple logons to the same account (three methods included)
WPF implements a program similar to the 360 Security defender Interface source code sharing C # implements the Boss key function C # converts all filenames in the specified directory to lowercase methods example of C # generic dictionary usage examples
C #. NET Implements currency conversion example