(PHP)如何避免科学计数法并显示实际的大数? [英] (PHP) How to avoid scientific notation and show the actual large numbers?

查看:471
本文介绍了(PHP)如何避免科学计数法并显示实际的大数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用PHP代码,预期结果将变为:

I have been working with the PHP code that the expected result will become :

1
101
10001
1000001
100000001
10000000001
1000000000001
100000000000001
10000000000000001
1000000000000000001

1
101
10001
1000001
100000001
10000000001
1000000000001
100000000000001
10000000000000001
1000000000000000001


最终输出是:


finally the output was :

1
101
10001
1000001
100000001
10000000001
1000000000001  //(10亿)(1000亿-1)仍显示实际数字,然后
1.0E + 14
1.0E + 16
1.0E + 18

1
101
10001
1000001
100000001
10000000001
1000000000001     // (1 billion) to (100 billion - 1) still showing the actual number, and then
1.0E+14
1.0E+16
1.0E+18


我在那里找到了一些解决方案!他们说使用 sprintf 或尝试使用 format_number .我都尝试过.

使用 sprintf 和结果:


I've found some solutions there! they said by using sprintf or trying format_number. I tried both.

using sprintf and the result :

$format_x = sprintf("%.0f ",$x);
echo $format_x.$br;

1
101
10001
1000001
100000001
10000000001
1000000000001
100000000000001
10000000000000000
1000000000000000000

1
101
10001
1000001
100000001
10000000001
1000000000001
100000000000001
10000000000000000
1000000000000000000


使用 format_number 和结果:

echo number_format($x, 0).$br;

1
101
10,001
1,000,001
100,000,001
10,000,000,001
1,000,000,000,001
100,000,000,000,001
10,000,000,000,000,000
1,000,000,000,000,000,000

1
101
10,001
1,000,001
100,000,001
10,000,000,001
1,000,000,000,001
100,000,000,000,001
10,000,000,000,000,000
1,000,000,000,000,000,000


,但仍未显示实际的大数字.好吧,这两种方法看起来不错,但与我想要的不匹配.有谁能解决这个问题?


but it still doesn't show the actual large numbers. well, the two ways was looks good but it doesn't fit with what i want. does anyone can resolve this?

推荐答案

您可以使用标准的 bc_math 库来处理大量操作.请注意,在这种情况下,您的数字将以字符串表示,但是库提供了在此类字符串下进行操作的特定方法.

You can use standard bc_math library to handle operations with large numbers. Please, note, that in this case your numbers will be represented as strings, but library provides specific methods for operations under such strings.

这篇关于(PHP)如何避免科学计数法并显示实际的大数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆