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

推荐订阅源

云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V2EX - 技术
V2EX - 技术
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
GbyAI
GbyAI
aimingoo的专栏
aimingoo的专栏
腾讯CDC
C
CERT Recently Published Vulnerability Notes
J
Java Code Geeks
WordPress大学
WordPress大学
博客园 - Franky
V
Vulnerabilities – Threatpost
小众软件
小众软件
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
有赞技术团队
有赞技术团队
The Hacker News
The Hacker News
T
The Blog of Author Tim Ferriss
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Martin Fowler
Martin Fowler
Webroot Blog
Webroot Blog
Attack and Defense Labs
Attack and Defense Labs
Google Online Security Blog
Google Online Security Blog
S
Securelist
Security Archives - TechRepublic
Security Archives - TechRepublic
T
Troy Hunt's Blog
Scott Helme
Scott Helme
Project Zero
Project Zero
T
Tailwind CSS Blog
The Register - Security
The Register - Security
A
About on SuperTechFans
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
The GitHub Blog
The GitHub Blog
Security Latest
Security Latest
L
LangChain Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
H
Hackread – Cybersecurity News, Data Breaches, AI and More
大猫的无限游戏
大猫的无限游戏
Cloudbric
Cloudbric
S
Security Affairs
博客园 - 叶小钗
Microsoft Security Blog
Microsoft Security Blog
H
Heimdal Security Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
PCI Perspectives
PCI Perspectives
The Cloudflare Blog
Last Week in AI
Last Week in AI
阮一峰的网络日志
阮一峰的网络日志
AI
AI

博客园 - 破宝

imdict-chinese-analyzer .NET转写版 SQLite全文检索(2) SQLite全文检索(1) 80块钱毁掉“猪八戒”的信誉 当 ASP.net Mobile Controls 碰到“中国特色”的 CMWAP / UNIWAP 闲话“正版”:正版软件和盗版软件的区别到底是什么? 闲话“正版”:真是因为“缺钱”吗? 又一个疑似Bug: XmlDataSource 控件的 Data 属性动态改变时,缓存不会自动失效 立此存照:System.Net.Mail 的 bug About GridView, HyperLinkField, UrlEncode 关于 GridView,HyperLinkField,UrlEncode WPF教程(译文)(第二部分) 破宝(percyboy)的自选精华版 破宝(percyboy)的留言板(2008/3~) WPF 教程(译文)(第一部分) Atlas 学习记录 ajaxnet4j beta Releases -- A Java Implementation of Ajax.NET Professional Library 好消息:Ajax.NET Professional open-sourced 及 ajaxnet4j 即将发布 NDoc Reloading: Kevin 留给我们的 NDoc 2.0 Alpha
有点郁闷:MSDN文档中MidpointRounding.AwayFromZero的翻译错误
破宝 · 2009-06-15 · via 博客园 - 破宝

很早就知道 Math.Round 方法实际上并不是我们上学时学到的“四舍五入”,而是 IEEE 标准定义的“银行家舍入”算法,通俗说法是“四舍六入五成双”(1.5→2, 4.5→4)。

当需要用到“四舍五入”算法时,.NET 1.x 中是需要自己实现(比如一种思路:正数加0.5后Math.Floor,负数减0.5后Math.Ceiling)。.NET 2.0 开始,Math.Round 方法提供了一个枚举选项 MidpointRounding.AwayFromZero 可以用来实现传统意义上的“四舍五入”。即: Math.Round(4.5, MidpointRounding.AwayFromZero) = 5。

不过MSDN文档中这个MidpointRounding.AwayFromZero的描述是“当一个数字是其他两个数字的中间值时,会将其舍入为两个值中绝对值较小的值。”弄的我很长时间没反应过来。

实际上从 .NET 2.0 发布以来,网上已经有很多人都指出了这个翻译错误(原文实际是 When a number is halfway between two others, it is rounded toward the nearest number that is away from zero.),实际上应该是取绝对值较大的值

可是很遗憾,.NET 3.0, .NET 3.5 的文档中,这个翻译错误依然没有改正。

P.S.附带地,你有没有注意过:Math.Floor(2.1) = 2 而 Math.Floor(-2.1) = -3,也就是所谓“向负无穷大方向舍入”; Math.Ceiling(2.1) = 3 而 Math.Ceiling(-2.1) = -2,也就是所谓“向正无穷大方向舍入”。比如说,Ceiling 的一个使用场景:一个袋子能装 10kg,则 21kg 货物需要三个袋子,如果是 -21kg 呢?Math.Ceiling 的上述行为,是否也不符合你的预期呢?