-1
我創建了我的第一個win32表單。我有一個錯誤,就是當消息框中顯示一個小數作爲輸出時,它會打印出小數點後10位。在控制檯程序中,我可以使用precision(2)命令將小數位設置爲2個位置,但我無法在win32中找到它。下面是代碼:在win32消息框中設置精度爲2位的小數
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
if (this->comboBox1->SelectedIndex == 0 && this->radioButton1->Checked == true) {
double a = Convert::ToDouble(this->textBox1->Text->Trim());
double b = Convert::ToDouble(this->textBox2->Text->Trim());
double sum = (b - a) * 100;
MessageBox::Show("$" + sum);
}
else if (this->comboBox1->SelectedIndex == 0 && this->radioButton2->Checked == true) {
double a = Convert::ToDouble(this->textBox1->Text->Trim());
double b = Convert::ToDouble(this->textBox2->Text->Trim());
double sum = (a-b) * 100;
MessageBox::Show("$" + sum);
}
if (this->comboBox1->SelectedIndex == 1 && this->radioButton1->Checked == true) {
double a = Convert::ToDouble(this->textBox1->Text->Trim());
double b = Convert::ToDouble(this->textBox2->Text->Trim());
double sum = (b - a) * 50;
MessageBox::Show("$" + sum);
}
else if (this->comboBox1->SelectedIndex == 1 && this->radioButton2->Checked == true) {
double a = Convert::ToDouble(this->textBox1->Text->Trim());
double b = Convert::ToDouble(this->textBox2->Text->Trim());
double sum = (a - b) * 50;
MessageBox::Show("$" + sum);
}
if (this->comboBox1->SelectedIndex == 2 && this->radioButton1->Checked == true) {
double a = Convert::ToDouble(this->textBox1->Text->Trim());
double b = Convert::ToDouble(this->textBox2->Text->Trim());
double sum = (b - a) * 50;
MessageBox::Show("$" + sum);
}
else if (this->comboBox1->SelectedIndex == 2 && this->radioButton2->Checked == true) {
double a = Convert::ToDouble(this->textBox1->Text->Trim());
double b = Convert::ToDouble(this->textBox2->Text->Trim());
double sum = (a - b) * 50;
MessageBox::Show("$" + sum);
}
}
這與消息框沒有任何關係。難道你不能將值轉換爲文本的方面,然後顯示該文本。 –
你真的不應該使用C++/CLI進行GUI開發;請看看C#代替。 –
我的朋友告訴我同樣的事情。我在一個C++類,我很無聊,所以我決定嘗試一些WINAPI。但是我將學習C#來處理我認真的GUI應用程序。謝謝 – AMD