限制double的小数位数

时间:2015-10-10 20:30:48

标签: vb.net math

如何限制双重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

1 个答案:

答案 0 :(得分:2)

你可以使用
ListBox1.Items.Add(Format(valfinale, "0.00"))

ListBox1.Items.Add(Math.Round(valfinale, 2))