Hej Integer kan inte innehålla decimaltal. Har prövat det men blir heltal som innan. Vad är felet?Problem med decimaler
Jag vill få fram summan av labels i decimaler. Nu blir det avrundat till heltal.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Label1.Text = TextBox1.Text * ("5,5").ToString
Label2.Text = TextBox2.Text * ("0,75").ToString
Label3.Text = TextBox3.Text * ("1,4").ToString
Label4.Text = TextBox4.Text * ("0,4").ToString
Label5.Text = TextBox5.Text * ("1").ToString
Dim intTotal As Integer
Dim int1 As Integer
Dim int2 As Integer
Dim int3 As Integer
Dim int4 As Integer
Dim int5 As Integer
' Get the values from the input boxes.
int1 = CInt(Label1.Text)
int2 = CInt(Label2.Text)
int3 = CInt(Label3.Text)
int4 = CInt(Label4.Text)
int5 = CInt(Label5.Text)
' Get the total and display it.
intTotal = int1 + int2 + int3 + int4 + int5
Label13.Text = CInt(intTotal) ****** Här vill jag ha summan i decimaler 2,45 ex
End SubSv: Problem med decimaler
Deklarera allt som Decimal istället.Sv:Problem med decimaler
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Label1.Text = TextBox1.Text * ("5,5").ToString
Label2.Text = TextBox2.Text * ("0,75").ToString
Label3.Text = TextBox3.Text * ("1,4").ToString
Label4.Text = TextBox4.Text * ("0,4").ToString
Label5.Text = TextBox5.Text * ("1").ToString
Dim intTotal As Decimal
Dim int1 As Decimal
Dim int2 As Decimal
Dim int3 As Decimal
Dim int4 As Decimal
Dim int5 As Decimal
' Get the values from the input boxes.
int1 = CInt(Label1.Text)
int2 = CInt(Label2.Text)
int3 = CInt(Label3.Text)
int4 = CInt(Label4.Text)
int5 = CInt(Label5.Text)
' Get the total and display it.
intTotal = int1 + int2 + int3 + int4 + int5
Label13.Text = CInt(intTotal)
End Sub