V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
KanadeCCCC

[求助&探讨] 前端大数值与特殊数值数据计算方案

  •  
  •   KanadeCCCC · Mar 11, 2022 · 2234 views
    This topic created in 1517 days ago, the information mentioned may be changed or developed.

    最近碰到前端大数据处理的问题,如下

       100000000.00000008 => 100000000.00000007
       1000000000000.00005 => 1000000000000
    

    暂时想到的是预先约束位数,以及考虑使用 bigNumber 类似的库来解决。V 友们有更好的解决方案么?

    theohateonion
        1
    theohateonion  
       Mar 11, 2022
    目前没有,使用字符串模拟计算是最好的方案,类似的库还有 https://github.com/nefe/number-precision
    KanadeCCCC
        2
    KanadeCCCC  
    OP
       Mar 11, 2022
    @theohateonion 感谢,这个受制于 JS 本身的规则,苦恼了一天,我试试看这个解决办法。
    AV1
        3
    AV1  
       Mar 11, 2022
    Jsonz
        4
    Jsonz  
       Mar 11, 2022
    无脑上库...
    KanadeCCCC
        5
    KanadeCCCC  
    OP
       Mar 11, 2022
    @DOLLOR 感谢回复,这个库在候选项中。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   945 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 20:17 · PVG 04:17 · LAX 13:17 · JFK 16:17
    ♥ Do have faith in what you're doing.