我想在结果中只显示2个十进制数字,但我不知道如何。 这是我的代码:
Public Class Form1
Dim data1 As Double
Dim data2 As Double
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
data1 = TextBox1.Text
data2 = TextBox2.Text
Label4.Text = (data1 / data2) * 100 & "Liter / 100 Km"
End Sub
Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
e.Handled = True
MsgBox("Csak szám", MsgBoxStyle.Critical, "Hiba")
End If
End Sub
Private Sub TextBox2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox2.KeyPress
If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
e.Handled = True
MsgBox("Csak szám", MsgBoxStyle.Critical, "Hiba")
End If
End Sub
End Class
答案 0 :(得分:-1)
data1.ToString( “C”); //将根据文化显示$ 1000.00,$ 1000,00等 // 要不就 data1.ToString( “N2”); 1000m.ToString( “F2”); //对于普通数字:1000.00,1000,00
从中复制 .md