从 MySQL 中获取长变量/数字并“压缩”它
假设我的数据库中有一个 10,000 位数字...
如果它被回显,这对于查看者来说会很滞后。
有没有办法只显示100(前100)?数字?
- 使用 php,或者(首选)使用 MySQL 只获取前 100 个...
Lets say I have a 10,000 digit number in my database...
This would be laggy for the viewer if it was echoed out.
Is there a way to display only like 100 (the first 100)? Digits?
-Either using php, or (Pref.) using MySQL to only get the first 100...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在显示这样的数字之前,MySQL 需要将如此大的数字存储为双精度型,或者您可以将其存储为字符串。实际上,双精度数只允许大约308位。如果将其存储为字符串,则可以使用子字符串和连接(带点)以您喜欢的任何精度将其转换为科学记数法。您可以计算字符串的长度以获得指数。当然你不能使用数据库来做数学。
为什么需要这种精度?
Before you can display such a number, MySQL would require such a large number to be stored as a double or you could store it as a string. Actually, doubles only allow about 308 digits. If you stored it as a string, you could convert it to scientific notation using substring and concatenation (with the dot) with whatever precision you like. You could count the length of the string to get the exponent. Of course you can't use the database to do math.
Why would you need this kind of precision?
为什么使用 PHP 来存储这些数字?什么样的网站需要这个功能?
您可能想使用 Perl、Python 或 Ruby 来完成此类任务。 Python 内置了对大数的支持。
Why are you using PHP to store such numbers? What kind of website needs that feature?
You may want to use Perl, Python, or Ruby for that kind of thing. Python has built-in support for large numbers.