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

推荐订阅源

宝玉的分享
宝玉的分享
IT之家
IT之家
Stack Overflow Blog
Stack Overflow Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
腾讯CDC
P
Palo Alto Networks Blog
Spread Privacy
Spread Privacy
S
Schneier on Security
NISL@THU
NISL@THU
WordPress大学
WordPress大学
酷 壳 – CoolShell
酷 壳 – CoolShell
P
Proofpoint News Feed
T
Threatpost
Scott Helme
Scott Helme
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Exploit Database - CXSecurity.com
I
Intezer
C
Check Point Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
C
Cyber Attacks, Cyber Crime and Cyber Security
S
Securelist
Security Latest
Security Latest
大猫的无限游戏
大猫的无限游戏
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
小众软件
小众软件
www.infosecurity-magazine.com
www.infosecurity-magazine.com
云风的 BLOG
云风的 BLOG
量子位
T
Tor Project blog
博客园 - 叶小钗
The Cloudflare Blog
Simon Willison's Weblog
Simon Willison's Weblog
T
Tailwind CSS Blog
W
WeLiveSecurity
Hacker News - Newest:
Hacker News - Newest: "LLM"
Attack and Defense Labs
Attack and Defense Labs
S
Security Affairs
罗磊的独立博客
Know Your Adversary
Know Your Adversary
Engineering at Meta
Engineering at Meta
G
Google Developers Blog
Help Net Security
Help Net Security
美团技术团队
P
Privacy International News Feed
The Hacker News
The Hacker News
Hugging Face - Blog
Hugging Face - Blog
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

博客园 - 我的bug

项目引入同一jar包不同版本处理 【笔记】redis实现类 【笔记】websockt一对一聊天java部分 【笔记】vue中websocket心跳机制 【笔记】MySQL删除重复记录保留一条 oss上传实例 jquery实现图片点击旋转 IDEA卡顿解决方法 斐波那契数列 【笔记】接口发送数据及接收 【笔记】获取新浪财经最新的USDT-CNY的汇率 【笔记】Java 信任所有SSL证书(解决PKIX path building failed问题) 【笔记】jquery判断两个日期之间相差多少天 【笔记】spring定时器时间配置实例 string 日期相加和相减 sql查询慢原因及优化 java小算法复习 找出一组数字中出现最多的字符 【转载】js清空cookie
【笔记】jquery加减乘除及科学计算法处理
我的bug · 2018-06-19 · via 博客园 - 我的bug
/**
 * 加法运算,避免数据相加小数点后产生多位数和计算精度损失。
 *
 * @param num1加数1 | num2加数2
 */
function numAdd(num1, num2) {
 var baseNum, baseNum1, baseNum2;
 try {
  baseNum1 = num1.toString().split(".")[1].length;
 } catch (e) {
  baseNum1 = 0;
 }
 try {
  baseNum2 = num2.toString().split(".")[1].length;
 } catch (e) {
  baseNum2 = 0;
 }
 baseNum = Math.pow(10, Math.max(baseNum1, baseNum2));
 return (num1 * baseNum + num2 * baseNum) / baseNum;
};
/**
 *减法运算,避免数据相减小数点后产生多位数和计算精度损失。
 *
 * @param num1被减数  |  num2减数
 */
function numSub(num1, num2) {
 var baseNum, baseNum1, baseNum2;
 var precision;// 精度
 try {
  baseNum1 = num1.toString().split(".")[1].length;
 } catch (e) {
  baseNum1 = 0;
 }
 try {
  baseNum2 = num2.toString().split(".")[1].length;
 } catch (e) {
  baseNum2 = 0;
 }
 baseNum = Math.pow(10, Math.max(baseNum1, baseNum2));
 precision = (baseNum1 >= baseNum2) ? baseNum1 : baseNum2;
 return ((num1 * baseNum - num2 * baseNum) / baseNum).toFixed(precision);
};
/**
 * 乘法运算,避免数据相乘小数点后产生多位数和计算精度损失。
 *
 * @param num1被乘数 | num2乘数
 */
function numMulti(num1, num2) {
 var baseNum = 0;
 try {
  baseNum += num1.toString().split(".")[1].length;
 } catch (e) {
 }
 try {
  baseNum += num2.toString().split(".")[1].length;
 } catch (e) {
 }
 return Number(num1.toString().replace(".", "")) * Number(num2.toString().replace(".", "")) / Math.pow(10, baseNum);
};
/**
 * 除法运算,避免数据相除小数点后产生多位数和计算精度损失。
 *
 * @param num1被除数 | num2除数
 */
function numDiv(num1, num2) {
 var baseNum1 = 0, baseNum2 = 0;
 var baseNum3, baseNum4;
 try {
  baseNum1 = num1.toString().split(".")[1].length;
 } catch (e) {
  baseNum1 = 0;
 }
 try {
  baseNum2 = num2.toString().split(".")[1].length;
 } catch (e) {
  baseNum2 = 0;
 }
 with (Math) {
  baseNum3 = Number(num1.toString().replace(".", ""));
  baseNum4 = Number(num2.toString().replace(".", ""));
  return (baseNum3 / baseNum4) * pow(10, baseNum2 - baseNum1);
 }
};
//处理科学计算法
function toNonExponential(num) {
    var m = num.toExponential().match(/\d(?:\.(\d*))?e([+-]\d+)/);
    return num.toFixed(Math.max(0, (m[1] || '').length - m[2]));
}