0

有人可以解释一下这行代码有什么问题

之前(示例 - 如何使用):

"value" => "27.50" //enforce the use of strings

之后

"value" => "round($_SESSION["Payment_Amount"], 2)" //Think of that Payment_Amount is 198,99 in session.

非常感谢您解释为什么会出错。

4

1 回答 1

2

I would suggest using a formatting function like sprintf or number_format instead of round.

"value" => sprintf('%0.2f', $_SESSION["Payment_Amount"])

For two reasons:

  1. It will return a string. It looks like you're quoting the value because you need it to be a string.
  2. It will display two digits after the decimal point. It looks like that's what you want, and round won't show them if there happen to be trailing zeros, because it returns a float, and floats don't show trailing zeros when they're converted to strings.
于 2018-10-04T22:47:06.327 回答