无法舍入或截断十进制Laravel

时间:2017-03-20 09:18:36

标签: php laravel

我在Laravel 4的控制器中遇到问题。我尝试用逗号后的2位数舍入(或截断)小数,但它不起作用。

我试过这样的事情:

round(888/100, 2);

或者:

floor(888*100)/100;

但我有8.880000000000001而不是8.88。 为什么呢?

(在这个例子中我拿这个号码但它可以是另一个号码)

2 个答案:

答案 0 :(得分:1)

四舍五入后试试这个:

Option Explicit

Sub KeepUniqueDomains()
    Dim Dict As Object
    Dim EmailArr As Variant
    Dim C As Range, LastRow As Long
    Dim Key As Variant

    Set Dict = CreateObject("Scripting.Dictionary")

    With Sheets("Sheet7") '<-- modify "Sheet7" with your sheet's name
        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

        For Each C In .Range("A2:A" & LastRow).Cells
            EmailArr = Split(C.Value, "@")

            If Not Dict.exists(EmailArr(1)) Then
                Dict.Add EmailArr(1), EmailArr(1)
            End If
        Next C
    End With

    Dim MsgStr As String
    For Each Key In Dict.keys
        MsgStr = MsgStr & Key & vbCr
    Next Key
    MsgBox "Unique domain names in the list are :" & vbCr & MsgStr
End Sub

答案 1 :(得分:1)

试试这个

number_format($number, 2, '.', ',');
// 2 = decimal places |  '.' = decimal seperator | ',' = thousand seperator