search

Home  >  Q&A  >  body text

Calculated value - PHP calculation method

What are the general methods of using PHP operations?

For example, it is used when calculating turnover
$sql = "select sum(`price`) from table";
$cprice = $dosql($sql);

//When cprice * 100 is found, the result type is float
It is said that float is not suitable for calculations. Will it have any impact? 
仅有的幸福仅有的幸福2755 days ago367

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-05-16 13:11:38

    It is best to use the int type, which is accurate to minutes when defining. Single-precision floating-point numbers use 4 bytes (32 bits) to represent floating-point numbers.
    Use IEEE754 standard computer floating-point numbers, which are represented internally in binary. For example: 7.22 is expressed in 32 bits. There is no way to express it in binary.
    So it’s not accurate.

    reply
    0
  • Cancelreply