C #. NET Implements currency conversion example

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.