C # currency format conversion instance analysis

Source: Internet
Author: User

The C # currency format conversion instance introduces you to some tips used in C # currency format conversion. I hope this instance will help you understand the Usage Details of C # currency format conversion, it is helpful for you to learn how to convert the C # currency format.

C # currency format conversion 1. format the input data to the currency format

This example uses the CurrencyGroupSeparator attribute of the NumberFormatInfo class to format the input data in the currency format. The CurrencyGroupSeparator attribute gets or sets a string that groups the digits on the left of the decimal point in the currency value. Run the program. In the input data text box, enter a number and click "format input data as currency". The effect is 5.13.

C # The main code for the application of the currency format is as follows:

 
 
  1.  private void button1_Click(object sender, EventArgs e)  
  2.  
  3. {  
  4.  
  5. NumberFormatInfo nfi = new CultureInfo("zh-CN", false).NumberFormat;  
  6.  
  7. nfi.CurrencyGroupSeparator = " ";  
  8.  
  9. textBox2.Text = Convert.ToDouble(textBox1.Text).ToString("c",nfi);  
  10.  
  11. }  

C # currency format conversion 2. How to convert the commodity lowercase amount to uppercase

This example describes how to convert the commodity amount to uppercase in lowercase. Run the program, enter the lower-case amount in the text box, and click OK to perform the conversion. The main code is as follows:

 
 
  1.  Private VoidButton#click (ObjectSender, EventArgs e)
  2.  
  3. {
  4.  
  5. String [] Scale = {"Minute", "angle", "Yuan", "Pick ",
  6. "Weight", "weight", "", "Pick", "weight", "weight", "", "Pick ",
  7. "Shanghai", "Shanghai", "MB", "Shanghai "};
  8.  
  9. String [] Base = {"zero", "one", "two", "three ",
  10. "Si", "Wu", "Lu", "Jun "};
  11.  
  12. String Temp = textBox1.Text. ToString ();
  13.  
  14. String Info =Null;
  15.  
  16. IntIndex = Temp. IndexOf (".", 0, Temp. Length); // you can check whether a decimal point exists.
  17.  
  18. If(Index! =-1)
  19.  
  20. {
  21.  
  22. Temp = Temp. Remove (Temp. IndexOf ("."), 1 );
  23.  
  24. For(IntI = Temp. Length; I> 0; I --)
  25.  
  26. {
  27.  
  28. IntData = Convert. ToInt16 (Temp [Temp. Length-I]);
  29.  
  30. Info + = Base [Data-48];
  31.  
  32. Info + = Scale [I-1];
  33.  
  34. }
  35. }
  36.  
  37. Else 
  38.  
  39. {
  40. For(IntI = Temp. Length; I> 0; I --)
  41.  
  42. {
  43. IntData = Convert. ToInt16 (Temp [Temp. Length-I]);
  44.  
  45. Info + = Base [Data-48];
  46.  
  47. Info + = Scale [I + 1];
  48.  
  49. }
  50. }
  51. TextBox2.Text = Info;
  52.  
  53. }

The basic content of the C # currency format conversion instance is introduced here. I hope you can understand and learn how to convert the C # currency format.

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.