如何限制双重valfinale
的小数位数1276.2815625
到
1276.28
我试过了math.round()
,但它不起作用
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim valinteret As Double
Dim valinitial As Double
Dim valannees As Double
Dim valintervale As Double
Dim valfinale As Double
Dim annees As Double
valinteret = Convert.ToInt32(txtinteret.Text) / 100
valinitial = Convert.ToInt32(txtinitial.Text)
valannees = Convert.ToInt32(Txtannees.Text)
valintervale = Convert.ToDouble(Txtintervale.Text)
ListBox1.Items.Add("vous investissez:" & valinitial.ToString())
For i = 1 To valannees Step valintervale
annees += +1
valfinale = valinitial * (1 + valinteret) ^ annees
ListBox1.Items.Add(valfinale)
Next
End Sub
End Class
答案 0 :(得分:2)
你可以使用
ListBox1.Items.Add(Format(valfinale, "0.00"))
或
ListBox1.Items.Add(Math.Round(valfinale, 2))