I have a list of numbers then I want to put comma on each number works fine, but the problem if number exceed to 14 my output become scientific format
我有一个数字列表然后我想在每个数字上使用逗号工作正常,但问题如果数量超过14我的输出成为科学格式
Like this 1,.,1,1,1,1,1,1,1,1,1,E,+,2,8
像这样的1,。,1,1,1,1,1,1,1,1,1,E,+,2,8
but i want to be like this 1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,
但我想像这样1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,
here's sample code below
这是下面的示例代码
<?php
$val = 11111111110000000000000000111;
$val = (string)$val; // convert into a string
$arr = str_split($val, "1"); // break string in 3 character sets
$val_new = implode(",", $arr); // implode array with comma
echo $val_new;
?>
Thanks
2 个解决方案
#1
1
This happens because the number is too large, so php automatically converts it into the scientific format. you can avoid this by defining the number as string initially (by putting it inside quotations)...try changing your code to this:
这是因为数字太大,所以php会自动将其转换为科学格式。您可以通过最初将数字定义为字符串(通过将其放在引号内)来避免这种情况...尝试将代码更改为:
$val = "11111111110000000000000000111";
and remove this line:
并删除此行:
$val = (string)$val; // convert into a string
let me know how it went.
让我知道它是怎么回事。
#2
2
This is because it exceeds the max value of an integer. There is nothing much you can do about it. Input that exceeds this limit will always be converted to a floating point representation. This means the input should immediatly be formatted as a string:
这是因为它超过了整数的最大值。你无能为力。超过此限制的输入将始终转换为浮点表示。这意味着输入应立即格式化为字符串:
$val = "11111111110000000000000000111";
$arr = str_split($val, 1); // break string in 3 character sets
$val_new = implode(",", $arr); // implode array with comma
echo $val_new;
#1
1
This happens because the number is too large, so php automatically converts it into the scientific format. you can avoid this by defining the number as string initially (by putting it inside quotations)...try changing your code to this:
这是因为数字太大,所以php会自动将其转换为科学格式。您可以通过最初将数字定义为字符串(通过将其放在引号内)来避免这种情况...尝试将代码更改为:
$val = "11111111110000000000000000111";
and remove this line:
并删除此行:
$val = (string)$val; // convert into a string
let me know how it went.
让我知道它是怎么回事。
#2
2
This is because it exceeds the max value of an integer. There is nothing much you can do about it. Input that exceeds this limit will always be converted to a floating point representation. This means the input should immediatly be formatted as a string:
这是因为它超过了整数的最大值。你无能为力。超过此限制的输入将始终转换为浮点表示。这意味着输入应立即格式化为字符串:
$val = "11111111110000000000000000111";
$arr = str_split($val, 1); // break string in 3 character sets
$val_new = implode(",", $arr); // implode array with comma
echo $val_new;