如何在PHP中乘以十进制数并获得带小数位的结果

I have the following code which multiplies a number (number is stored in a database) and I then download the result to a CSV file. The resulting number is given as a whole number rather than including a decimal place.

Current Code

<? return ((float) $amount*1) ?>

Current Result: 2 x 2.13 = 4

Desired Result: 2 x 2.13 = 4.26

In this example $amount = 2.13

Can anyone please suggest an edit to get this working?

You can use number_format for that:

number_format(2.13 * 2, 2); // "4.26"

See https://3v4l.org/GlARW for performance related information.