字符串精度

时间:2015-12-30 17:07:06

标签: java string double decimal

我有以下代码:

 String price="9000.89";
        double basePrice =10000;

        String dis= String.valueOf(((basePrice - Double
                .parseDouble(price)) * 100 / basePrice));
 System.out.println(dis);

它输出为“9.991100000000007”,但我需要2个小数点。知道怎么做吗?

预期产量:9.99

3 个答案:

答案 0 :(得分:1)

functools

答案 1 :(得分:0)

我会推荐

Sub Datacopy()

    Dim ws As Worksheet

    With Application
        .ScreenUpdating = False
    End With

    Application.DisplayAlerts = False

    Set ws = Sheets("email")

    For Each Cell In ws.Columns("B").Cells

        Dim file1 As String

        file1 = Cell.Offset(0, 3).Text

            Sheets("cell.value").Range("A1:L500").Copy
            Workbooks.Add.Worksheets("Sheet1").Range("A1").PasteSpecial (xlPasteAllUsingSourceTheme)
            Worksheets("Sheet1").Range("A1").PasteSpecial (xlPasteComments)
            ActiveWorkbook.SaveAs Filename:=file1
            ActiveWorkbook.Close

    Next Cell

    Application.DisplayAlerts = True

    With Application
        .ScreenUpdating = True
    End With

    MsgBox ("Finished making files!")

End Sub

答案 2 :(得分:-3)

你可以使用:

Math.round(number * 100.0) / 100.0;