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 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

Related Article

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.