Get the App
SLTechnology News&Howtos  ›  Development  › 

How to convert C # currency format

Shulou Source: shulou.com Published: 2022-06-02 09:07:58 10月04日 Update

This article mainly introduces "how to transform C # currency format". In daily operation, I believe many people have doubts about how to convert C # currency format. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the question of "how to transform C # currency format"! Next, please follow the editor to study!

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

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

The main codes for the application of C# currency format are as follows:

Private void button1_Click (object sender, EventArgs e) {NumberFormatInfo nfi = new CultureInfo ("zh-CN", false) .NumberFormat; nfi.CurrencyGroupSeparator = ""; textBox2.Text = Convert.ToDouble (textBox1.Text) .ToString ("c", nfi);}

C # currency format conversion 2. How to convert lowercase amount of goods to uppercase

This example mainly introduces how to convert the amount of goods from lowercase to uppercase. Run the program, enter the lowercase amount in the text box, and click the [OK] button to perform the conversion. The main code is as follows:

Private void button1_Click (object sender, EventArgs e) {String [] Scale = {"fen", "jiao", "yuan", "pick up", "hundred", "thousand", "ten thousand", "pick up", "hundred", "thousand", "hundred", "billion", "pick", "hundred", "thousand", "trillion", "pick up", "hundred", "thousand"} String [] Base = {"zero", "one", "II", "three", "restaurant", "Wu", "Lu", "Qi", "Qing", "nine"}; String Temp = textBox1.Text.ToString (); String Info = null; int index = Temp.IndexOf (".", 0m temp. Length) / / determine whether there is a decimal point if (index! =-1) {Temp = Temp.Remove (Temp.IndexOf ("."), 1); for (int I = Temp.Length; I > 0; Imam -) {int Data = Convert.ToInt16 (temp [temp. Length-I]); Info + = Base [Data-48]; Info + = Scale [I-1];} else {for (int I = Temp.Length; I > 0) Info -) {int Data = Convert.ToInt16 (temp [temp. Length-I]); Info + = Base [temp-48]; Info + = Scale [item1];}} textBox2.Text = Info;} this ends the study of "how to transform the C # currency format", hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Format currency currency input data learning lowercase amount code commodity uppercase instance decimal decimal point properties buttons numbers text more programs Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology OPPO Reno Shulou Information MySQL Linux