Instance 365 (1) --------- format as currency

Source: Internet
Author: User

I:

Ii. Code
Using System; using System. collections. generic; using System. componentModel; using System. data; using System. drawing; using System. linq; using System. text; using System. windows. forms; namespace Format {public partial class Frm_Main: Form {public Frm_Main () {InitializeComponent ();} private void btn_Set_Click (object sender, EventArgs e) {double P_dbl_temp; // define the double type variable if (double. tryParse (txt_str.Text, Out P_dbl_temp) // verify that the input is correct and assign a value {// Globalization, ystem. the Globalization namespace contains a class that defines information related to the region, including the language, country/region, // calendar in use, date, currency, and Number Format mode, and the sort order of strings. System. Globalization. NumberFormatInfo GN = // instantiate the NumberFormatInfo object. NumberFormatInfo provides specific regional information for formatting and Analysis of numeric values. New System. globalization. cultureInfo ("zh-CN", false ). numberFormat; // CultureInfo ("zh-CN", false) is based on the region specified by the name and based on the Boolean value (whether to use the locale selected by the user in the System) to initialize a new instance of the CultureInfo class // NumberFormat to obtain or set NumberFormatInfo, which defines the format GN that is applicable to the culture, displays numbers, currencies, and percentages. currencyGroupSeparator = ","; // gets or sets a string that groups the digits on the left of the decimal point in the currency value. Txt_result.Text = P_dbl_temp.ToString ("C", GN); // format and display the format as currency. Currency 2.5.ToString ("C") ¥ 2. 50} else {MessageBox. show ("enter the correct currency value! "," Prompt! "); // Output error message }}}}

 

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.