Display float value w/o scientific notation

后端 未结 4 504
长发绾君心
长发绾君心 2020-11-27 20:00

When i make the following multiplication in PHP:

$ret = 1.0 * 0.000000001;

i get the result: 1.0E-9

I want to convert this result i

4条回答
  •  心在旅途
    2020-11-27 20:39

    To align to your system's settings and limitations, you could use serialize_precision to get the most accurate result possible.

    echo rtrim(sprintf('%.'.ini_get('serialize_precision').'f', $ret));
    

    I do not recommend using the non-locale aware %F since your question only makes sense for display purposes. Respecting locale makes for a better UX.

提交回复
热议问题