Click here to Skip to main content
15,879,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Brother,
Please help
I had used calculating Number as per code below it working fine (Example 12 + 18 = 30 ) but now I want to calculate decimals also (example 12.4 + 17.6 = Error) please help for this resolve this. my code is below :

lbltotalscore.Text = Convert.ToInt32(txtscore1.Text) + Convert.ToInt32(txtscore2.Text) + Convert.ToInt32(txtscore3.Text)
Posted
Comments
[no name] 13-Apr-14 9:25am    
Well you are getting that error because the string "12.4" cannot be converted to an integer.

I'd suggest to start here: Data Type Summary (Visual Basic)[^]
Why? Please read it to find out ;)
 
Share this answer
 
v2
12.4 and 17.6 are not valid Integers. You should use a Double. You could use Convert.ToDouble to convert the input to a Double, but it is a lot better to use Double.TryParse to check whether the given input is valid:
VB.NET
Dim first As Double
Dim second As Double
Dim third As Double
If Double.TryParse(txtscore1.Text, first) AndAlso Double.TryParse(txtscore2.Text, second) AndAlso Double.TryParse(txtscore3.Text, third) Then
	Dim sum As Double = first + second + third
	lbltotalscore.Text = sum.ToString()
Else
        ' one of the given values is invalid
End If
 
Share this answer
 
v3
Comments
Maciej Los 13-Apr-14 12:16pm    
Nice. I was bit lazy ;)
+5!
Thomas Daniels 13-Apr-14 12:17pm    
Thank you!
Sajid H. A. Rashid 14-Apr-14 8:50am    
Thankyou very much
Thomas Daniels 14-Apr-14 8:53am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900