Default Number of Decimal Places to Output in PHP

前端 未结 6 1376
执念已碎
执念已碎 2020-12-18 13:37

I do my php work on my dev box at home, where I\'ve got a rudimentary LAMP setup. When I look at my website on my home box, any numbers I echo are automatically truncated t

6条回答
  •  感动是毒
    2020-12-18 14:20

    thanks for all the answers - the solution was to cast the return value of the method responsible to a float. I.e. it was doing

    return someNumber.' grams';
    

    I just changed it to

    return (float)someNumber.' grams';
    

    then PHP truncated any trailing zeroes when required.

    Can someone close this?

提交回复
热议问题