【问题标题】:How to convert very small, normal, Large, scientific number to string in php如何在php中将非常小的、正常的、大的、科学的数字转换为字符串
【发布时间】:2021-06-16 08:27:59
【问题描述】:

我使用了这个函数,但它不适用于非常大和非常小的数字

function  convert($number)
{
return  (string)sprintf("%.40f",  floatval($number));
}
//example 1
// convert(10);
//"10.0000000000000000000000000000000000000000" correct
//
//example 2
// convert(1.0464844434049273e-9)
// "0.0000000010464844434049272962108666736101" incorrect
// "0.0000000010464844434049273" correct
//
//example 3
// convert(0.0000010464844434049273)
// "0.0000010464844434049273375698973012615234" incorrect
// "0.0000010464844434049001" correct

我在here查看了这些数字

在 php 或 laravel 中有什么好的包可以处理这些类型的数字吗?

【问题讨论】:

    标签: php laravel numbers scientific-notation largenumber


    【解决方案1】:

    一些有帮助的回答。

    第一:

    请注意,PHP 在内部使用有符号整数。大小取决于您的系统。

    32位系统:

    2^(32-1) = 2147483648 64位系统:

    2^(64-1) = 9223372036854775808 -1,因为 1 位是为标牌标志保留的。

    第二:

    要处理大数字并将其用作字符串,请尝试使用BCMath functions

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多