Jes Sie

Jes Sie

  • 706
  • 1.2k
  • 277.8k

converting to decimal

Oct 9 2017 12:03 AM
I need assistance again ;( . I have this code snippet below which converts the textbox to a decimal:
  1. private void ComputeTotalPremium()  
  2.         {  
  3.             try  
  4.             {  
  5.                 int persons = Convert.ToInt32(txtTravellingPersons.Text);  
  6.                 decimal premium = Convert.ToDecimal(lblPremium.Text);  
  7.                 decimal Total;  
  8.                 Total = persons * premium;  
  9.                 txtTotalPremium.Text = Total.ToString("N2", CultureInfo.InvariantCulture);  
  10.             }  
  11.             catch (Exception ex)  
  12.             {  
  13.                 if (ex is FormatException)  
  14.                 {  
  15.   
  16.                 }  
  17.                 else  
  18.                 {  
  19.                     throw ex;  
  20.                 }  
  21.             }  
  22.         }  
The value of txtTravellingPersons.Text is 1. 
The original value of lblPremium.Text is 16.00, but when the value was converted to decimal (decimal premium) the 16.00 becomes 1600. 
 
Please note that this piece of code was working ever since I'm using it but now it failed. Thanks for any assistance. 

Answers (13)