Example Application: Percentage Conversion

 Introduction
 This application shows different ways to convert a decimal to a percentage value. The values include regular decimals and fractions. Another part of the exercise shows how to convert a percentage value to a decimal.
 Practical Learning: Creating the Application
1. To create a new application, on the main menu, click File -> New Project...
2. In the middle list, click Windows Forms Application
3. Change the Name to PercentageConversions1
4. Click OK
5. Design the form as follows:

 Control Text Name ReadOnly TextAlign GroupBox Converting a Percentage to Decimal Label V&alue: TextBox 5 txtPercentage1 Right Label % of TextBox 10 txtValue1 Right Button = btnConvert1 TextBox txtValue1 True Right GroupBox Converting a Fraction to a Percentage TextBox 3 txtNumerator Right Label / TextBox 4 txtDenominator Right Button = btnFractionToPercent TextBox txtPercentage2 True Right Label % GroupBox Converting a Decimal to Percentage Label Val&ue: TextBox 0.125 txtDecimal1 Right Button = btnDecimalToPercent TextBox txtPercentage3 True Right Label % GroupBox Converting a Percentage to Decimal Label Valu&e: TextBox 75 txtPercentage4 Right Label % Button = btnPercentToDecimal TextBox txtDecimal2 True Right Button Close btnClose
6. Double-click the first = button
7. Implement its event as follows:
```System::Void btnConvert1_Click(System::Object^  sender, System::EventArgs^  e)
{
double percent = 0.00;
double value = 0.00;
double result;

try
{
percent = double::Parse(txtPercentage1->Text);
}
catch(FormatException ^)
{
MessageBox::Show(L"Invalid Percent Value", L"Percentage Conversion");
}

try
{
value = double::Parse(txtValue1->Text);
}
catch(FormatException ^)
{
MessageBox::Show(L"Invalid Value to Convert", L"Percentage Conversion");
}

result = percent * value / 100;
txtResult1->Text = result.ToString(L"F");
}```
9. Double-click the second = button
10. Implement its event as follows:
```System::Void btnFractionToPercent_Click(System::Object^  sender,
System::EventArgs^  e)
{
double numerator = 0.00;
double denominator = 0.00;
double result;

try
{
numerator = double::Parse(txtNumerator->Text);
}
catch(FormatException ^)
{
MessageBox::Show(L"Invalid Numerator", L"Percentage Conversion");
}

try
{
denominator = double::Parse(txtDenominator->Text);
}
catch(FormatException ^)
{
MessageBox::Show(L"Invalid Value to Convert",
L"Percentage Conversion");
}

result = (numerator / denominator) * 100;
txtPercentage2->Text = result.ToString(L"F");
}```
12. Double-click the third = button
13. Implement its event as follows:
```System::Void btnDecimalToPercent_Click(System::Object^  sender,
System::EventArgs^  e)
{
double value = 0.00;
double result;

try
{
value = double::Parse(txtDecimal1->Text);
}
catch(FormatException ^)
{
MessageBox::Show(L"Invalid Value to Convert",
L"Percentage Conversion");
}

result = value * 100;
txtPercentage3->Text = result.ToString(L"F");
}```
15. Double-click the last = button
16. Implement its event as follows:
```System::Void btnPercentToDecimal_Click(System::Object^  sender,
System::EventArgs^  e)
{
double value = 0.00;
double result;

try
{
value = double::Parse(txtPercentage4->Text);
}
catch(FormatException ^)
{
MessageBox::Show(L"Invalid Value to Convert",
L"Percentage Conversion");
}

result = value / 100;
txtDecimal2->Text = result.ToString(L"F");
}```
```System::Void btnClose_Click(System::Object^  sender, System::EventArgs^  e)