Reputation: 3980
How does one keep it a decmail without converting it as a string. I dont want to have to cahnge it to text as I am using value changed event to trigger a sum
if (!IsPostBack)
{
clientearningscic.Value = (decimal) _dal.getiandEData(_myuser.id, "clientearningscic") ;
otherincomeonecic.Text = _dal.getiandEData(_myuser.id, "otherincomethreecic").ToString("n2");
}
clientearningscic.ValueChanged += sumEarnings;
Any ideas would help me allot
private void sumEarnings(object sender, EventArgs e)
{
int total = Convert.ToInt16(clientearningscic.Text) + Convert.ToInt16(partnerearningscic.Text) + Convert.ToInt16(incomesupportcic.Text) + Convert.ToInt16(childtaxcreditcic.Text) + Convert.ToInt16(workingtaxcreditcic.Text) + Convert.ToInt16(pensioncic.Text) + Convert.ToInt16(childbenefitcic.Text) + Convert.ToInt16(chidlmaintenancecic.Text) + Convert.ToInt16(nondependantscontributioncic.Text) + Convert.ToInt16(otherincomeonecic.Text) + Convert.ToInt16(otherincometwocic.Text) + Convert.ToInt16(otherincomethreecic.Text);
lblTotalIcome.Text = total.ToString();
calcTotal();
}
Upvotes: 1
Views: 60
Reputation: 967
Converting the text values to the Int16 datatype will not allow any decimals. Try converting these to double, decimal, or float.
To round the value to a certain number of decimals, use
Math.Round(decimal val, # of decimals);
Upvotes: 2
Reputation: 1156
You're saving it as an integer. Integers support whole numbers from -2,147,483,648 to 2,147,483,647. But they don't support decimal values.
To use decimal values, you can't use int
but you can use float
or double
.
Upvotes: 0