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

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
P
Privacy International News Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Troy Hunt's Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Attack and Defense Labs
Attack and Defense Labs
S
Secure Thoughts
V2EX - 技术
V2EX - 技术
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
O
OpenAI News
Cloudbric
Cloudbric
Google Online Security Blog
Google Online Security Blog
Schneier on Security
Schneier on Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Help Net Security
Help Net Security
Cyberwarzone
Cyberwarzone
G
GRAHAM CLULEY
L
Lohrmann on Cybersecurity
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Spread Privacy
Spread Privacy
NISL@THU
NISL@THU
N
News and Events Feed by Topic
T
Tenable Blog
S
Security @ Cisco Blogs
N
News and Events Feed by Topic
The Hacker News
The Hacker News
C
CXSECURITY Database RSS Feed - CXSecurity.com
宝玉的分享
宝玉的分享
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google DeepMind News
Google DeepMind News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
V
Visual Studio Blog
P
Proofpoint News Feed
Webroot Blog
Webroot Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 三生石上(FineUI控件)
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Jina AI
Jina AI
雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
Hugging Face - Blog
Hugging Face - Blog
腾讯CDC
L
LangChain Blog
The Register - Security
The Register - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东

博客园 - 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)
}