gpt4 book ai didi

javascript - 如何在 JavaScript 中获取大数字的精确值字符串?

转载 作者:行者123 更新时间:2023-11-28 07:31:39 25 4
gpt4 key购买 nike

我知道 JavaScript 数字只是“ double ”数字,小数部分只有 52 位精度。然而,对于巨大的数字来说,REAL JavaScript 数字似乎具有更实用的精度。

例如,预定义常量Number.MAX_VALUE表示Number类型的最大正有限值,大约为1.7976931348623157e+308。在这里,我可以使用模运算符访问该值的尾随数字。

> Number.MAX_VALUE
1.7976931348623157e+308
> Number.MAX_VALUE % 10000000000
4124858368

根据这个结果,我可以假设这个数字是 7fef ffff ffff ffff ,它表示 (1 + (1 − 2 ** −52)) × 2 ** 1023 ( Wikipedia ) 并且可以是准确转录如下:

179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368

...我们只看到了这 309 位数字中的尾随 10 位数字。所以我认为每个 JavaScript 数字都必须有精确十进制形式的数字。

我的问题是:如何在 JavaScript 中获取这个 309 位数字的字符串?像 Number.MAX_VALUE/10000000000 % 10000000000 这样的挑战因为如此巨大而失败。

此外,像 Number.MIN_VALUE 这样的小数字怎么样?这必须是以下小数形式的分数。

0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004940656458412465441765687928682213723650598026143247644255856825006755072702087518652998363616359923797965646954457177309266567103559397963987747960107818781263007131903114045278458171678489821036887186360569987307230500063874091535649843873124733972731696151400317153853980741262385655911710266585566867681870395603106249319452715914924553293054565444011274801297099995419319894090804165633245247571478690147267801593552386115501348035264934720193790268107107491703332226844753335720832431936092382893458368060106011506169809753078342277318329247904982524730776375927247874656084778203734469699533647017972677717585125660551199131504891101451037862738167250955837389733598993664809941164205702637090279242767544565229087538682506419718265533447265625

最佳答案

MAX_VALUE 的所有数字为:1797693134862315700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000

查看下面的代码:

http://howjs.com/?%3Aload%20http%3A%2F%2Fwww.javascriptoo.com%2Fapplication%2Fhtml%2Fjs%2FMikeMcl%2Fbig.js%2Fbig.min.js%0A%0Avar%20max%20%3D%20new%20Big(%20Number.MAX_VALUE%20)%3B%0Amax.toFixed()%3B

关于javascript - 如何在 JavaScript 中获取大数字的精确值字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29061937/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com