private void btn_Get_Click(object sender, EventArgs e) { double P_dbl_value; //定义double类型变量 if (double.TryParse(txt_input.Text, out P_dbl_value)) //判断输入是否正确 { NumberFormatInfo GN = //实例化NumberFormatInfo对象 new CultureInfo("zh-CN", false).NumberFormat; GN.CurrencyDecimalDigits = Convert.ToInt32(cbox_select.Text); //设置保留位数 txt_output.Text = P_dbl_value.ToString("C", GN); //将输入的小数转换为货币形式 } else { MessageBox.Show("请输入正确的数值!", "提示!");//用户提示信息 } }
private void btn_Get_Click(object sender, EventArgs e) { double P_dbl_value; //定義double類型變數 if (double.TryParse(txt_input.Text, out P_dbl_value)) //判斷輸入是否正確 { NumberFormatInfo GN = //實例化NumberFormatInfo物件 new CultureInfo("zh-CN", false).NumberFormat; GN.CurrencyDecimalDigits = Convert.ToInt32(cbox_select.Text); //設定保留位數 txt_output.Text = P_dbl_value.ToString("C", GN); //將輸入的小數轉換為貨幣形式 } else { MessageBox.Show("請輸入正確的數值!", "提示!");//用戶提示訊息 } }