在 Javascript 中以非指数/短形式转换/表达双数
我在 Javascript 中有一个双精度值,例如,其值为 1.0883076389305e-311。 我想用以下形式表达它,例如使用 'bc' 实用程序来计算扩展/更高精度/比例形式:
$ bc
scale=400
1.0883076389305000*10^-311
.0000000000000000000000000000000000000000000000000000000000000000000\
00000000000000000000000000000000000000000000000000000000000000000000\
00000000000000000000000000000000000000000000000000000000000000000000\
00000000000000000000000000000000000000000000000000000000000000000000\
00000000000000000000000000000000000000010883076389305000000000000000\
0000000000000000000000000000000000000000000000000000000000000
我需要一个 Javascript bigint 库或代码来生成与具有扩展/更高精度的字符串相同的输出数字的精度形式。
谢谢!
I have a double in Javascript whose value is, for example, 1.0883076389305e-311.
I want to express it in the following form, using as example the 'bc' utility to calculate the expanded/higher precision/scale form:
$ bc
scale=400
1.0883076389305000*10^-311
.0000000000000000000000000000000000000000000000000000000000000000000\
00000000000000000000000000000000000000000000000000000000000000000000\
00000000000000000000000000000000000000000000000000000000000000000000\
00000000000000000000000000000000000000000000000000000000000000000000\
00000000000000000000000000000000000000010883076389305000000000000000\
0000000000000000000000000000000000000000000000000000000000000
I need a Javascript bigint library or code to produce the same output as a string with the expanded/higher precision form of the number.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这很可怕,但适用于我能想到的每个测试用例:
如果您发现一个无法正确解析的数字,即
n !== parseFloat(n.toFullFixed())
,请让我知道它是什么!This is horrible, but works with every test case I can think of:
If you find a number that doesn't parse back correctly, i.e.
n !== parseFloat(n.toFullFixed())
, please let me know what it is!// 只要你处理的是数字字符串而不是数字,你就可以
使用字符串方法将指数大小和精度转换为零
// So long as you are dealing with strings of digits and not numbers you can
use string methods to convert exponential magnitude and precision to zeroes