search

Home  >  Q&A  >  body text

How to handle data in the form of 3.5527136788005e-15 in PHP gracefully

-3.5527136788005e-15
3.5527136788005e-15

php Under what circumstances will such scientific notation appear?
Is there a function that can directly approximate 0?
Have you ever encountered this?

PHP中文网PHP中文网2746 days ago1295

reply all(2)I'll reply

  • 仅有的幸福

    仅有的幸福2017-05-24 11:35:46

    $num = 3.5527136788005e-15;
    
    var_dump(number_format($num));
    

    One step to get it right:

    $num = $num < 1 ? 0 : number_format($num, 2);
    var_dump($num);

    Reference: number_format

    reply
    0
  • 世界只因有你

    世界只因有你2017-05-24 11:35:46

    If the decimal point exceeds a few decimal points, it will appear and can be set. If the data is not required to be accurate, rounding can be done

    reply
    0
  • Cancelreply