惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
SegmentFault 最新的问题
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Attack and Defense Labs
Attack and Defense Labs
F
Full Disclosure
Vercel News
Vercel News
N
News | PayPal Newsroom
The GitHub Blog
The GitHub Blog
H
Hacker News: Front Page
H
Heimdal Security Blog
P
Privacy International News Feed
博客园 - 司徒正美
Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cisco Blogs
L
Lohrmann on Cybersecurity
D
Docker
Recent Announcements
Recent Announcements
Security Archives - TechRepublic
Security Archives - TechRepublic
人人都是产品经理
人人都是产品经理
C
CXSECURITY Database RSS Feed - CXSecurity.com
P
Proofpoint News Feed
T
Tailwind CSS Blog
C
Check Point Blog
博客园 - 叶小钗
Google Online Security Blog
Google Online Security Blog
Martin Fowler
Martin Fowler
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
S
Secure Thoughts
博客园 - Franky
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
P
Palo Alto Networks Blog
Latest news
Latest news
量子位
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 三生石上(FineUI控件)
The Cloudflare Blog
Last Week in AI
Last Week in AI
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Cyberwarzone
Cyberwarzone
小众软件
小众软件
Cisco Talos Blog
Cisco Talos Blog
Hacker News: Ask HN
Hacker News: Ask HN
T
Threatpost
T
Tenable Blog
P
Privacy & Cybersecurity Law Blog
WordPress大学
WordPress大学

博客园 - DreamTrue

发布新浪微博API SDK,附Demo地址!! NHibernate N+1问题实例分析和优化 可以防止重复提交的问题 - DreamTrue - 博客园 验证电话,手机,小灵通较正确的正则表达式 RegisterClientScriptBlock失效的问题 - DreamTrue - 博客园 程序员朋友们,注意保护眼睛啊!! 基础知识补遗-短路运算符和非短路运算符 用Response将字符串输出到文本(弹出文件下载框) - DreamTrue - 博客园 关于应用WCF X.509证书验证的小结 终于看完了《WCF服务编程》 什么是有状态的服务? 谁能帮我解答《WCF服务编程》第4章实例管理的疑问? 准备购买新书 ADO.Net EF Start (3):实体数据模型(MSDN)EDM1.0版 ADO.Net EF Start (2):Overview asp.net页面防止按钮重复提交的小技巧 ADO.Net EF Start (1):ADO.NET 实体框架概述(MSDN) Asp.net Ajax【客户端三】异步调用 Asp.net Ajax【客户端二】Sys.Net.WebRequest
JavaScript 乘法bug及格式化小数位数
DreamTrue · 2008-10-15 · via 博客园 - DreamTrue

格式化
function formatNumber (num, decplaces) {
    // convert in case it arrives as a string value
    num = parseFloat(num);
    // make sure it passes conversion
    if (!isNaN(num)) {
        // multiply value by 10 to the decplaces power;
        // round the result to the nearest integer;
        // convert the result to a string
        var str = "" + Math.round (eval(num) * Math.pow(10,decplaces));
        // exponent means value is too big or small for this routine
        if (str.indexOf("e") != -1) {
            return "Out of Range";
        }
        // if needed for small values, pad zeros
        // to the left of the number
        while (str.length <= decplaces) {
            str = "0" + str;
        }
        // calculate decimal point position
        var decpoint = str.length - decplaces;
        // assemble final result from: (a) the string up to the position of
        // the decimal point; (b) the decimal point; and (c) the balance
        // of the string. Return finished product.
        return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
    } else {
        return "NaN";
    }
}

乘法Bug
function mul(n1, n2) {
    var m=0, s1=n1.toString(), s2=n2.toString();
    try {
        m += s1.split(".")[1].length
    } catch(e) {
    }
    try {
        m += s2.split(".")[1].length
    } catch(e){
    }
    return Number(s1.replace(".","")) * Number(s2.replace(".","")) / Math.pow(10, m)
}