Private Sub toto_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles toto.LostFocus Dim sp As String sp = 1 / 2 sp = sp.Substring(1, 1) Dim rs As String Try Double.Parse(toto.Text) toto.Text = Double.Parse(toto.Text).ToString("#0.00#") rs = toto.Text.Substring(toto.Text.IndexOf(sp)) If rs.Length - 1 > 2 Then MessageBox.Show("plus de 2 chiffre après" & sp) Exit Sub End If Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub
Label1.Text = "45" Try Double.Parse(Label1.Text) Label1.Text = Double.Parse(Label1.Text).ToString("#0.00#") Catch ex As Exception MessageBox.Show(ex.Message) End Try
Label1.Text = "45" Try Label1.Text = Double.Parse(Label1.Text).ToString("#0.00#") Catch ex As Exception MessageBox.Show(ex.Message) End Try
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionmabox.Text = mabox.Text.Replace(".", ",")qui fait accepter donc la "," ou le "."
C.Text = valC.ToString("0.00")qui met donc les 2 chiffres après la virgule
Try toto.Text = Double.Parse(toto.Text).ToString("#0.00#") Catch ex As Exception MessageBox.Show(ex.Message) End Try
Private Sub Calcul_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calcul.Click ' on accepte aussi bien la virgule que le point pour les nombres décimaux TOTO.Text = TOTO.Text.Replace(".", ",") ........... .ValTOTO = Convert.ToDouble(TOTO.Text) If TOTO.Text.Length - TOTO.Text.IndexOf(",") > 3 Then MessageBox.Show("le paramètre TOTO a plus de 2 chiffres après la virgule", "Erreur saisie", MessageBoxButtons.OK, MessageBoxIcon.Error) Exit Sub End If TOTO.Text = .valTOTO.ToString("0.00") ' 2 chiffres après la virgule
Private Sub calcul_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calcul.Click Dim sp As String sp = 1 / 2 sp = sp.Substring(1, 1) Dim rs As String Try Double.Parse(toto.Text) toto.Text = Double.Parse(toto.Text).ToString("#0.00#") rs = toto.Text.Substring(toto.Text.IndexOf(sp)) If rs.Length - 1 > 2 Then MessageBox.Show("plus de 2 chiffre après" & sp) Exit Sub End If Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub