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:
- 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 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:
- Private VoidButton#click (ObjectSender, EventArgs e)
-
- {
-
- String [] Scale = {"Minute", "angle", "Yuan", "Pick ",
- "Weight", "weight", "", "Pick", "weight", "weight", "", "Pick ",
- "Shanghai", "Shanghai", "MB", "Shanghai "};
-
- String [] Base = {"zero", "one", "two", "three ",
- "Si", "Wu", "Lu", "Jun "};
-
- String Temp = textBox1.Text. ToString ();
-
- String Info =Null;
-
- IntIndex = Temp. IndexOf (".", 0, Temp. Length); // you can check whether a decimal point exists.
-
- If(Index! =-1)
-
- {
-
- Temp = Temp. Remove (Temp. IndexOf ("."), 1 );
-
- For(IntI = Temp. Length; I> 0; I --)
-
- {
-
- IntData = Convert. ToInt16 (Temp [Temp. Length-I]);
-
- Info + = Base [Data-48];
-
- Info + = Scale [I-1];
-
- }
- }
-
- Else
-
- {
- For(IntI = Temp. Length; I> 0; I --)
-
- {
- IntData = Convert. ToInt16 (Temp [Temp. Length-I]);
-
- Info + = Base [Data-48];
-
- Info + = Scale [I + 1];
-
- }
- }
- TextBox2.Text = Info;
-
- }
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.