--- title: 各语言数学运算支持 tags: 计算机数字 abbrlink: 2bb0e876 date: 2022-09-28 19:58:34 --- # 计算机中的数; 数字在二进制中表示方法; 计算原理 书; # 格式化 对于货币; 如补零操作; oracle fff999之类的字符表示; 各个语言也有自己的表示方法; # 取值:有限的存储不能表示无限的数 四舍五入;是一个经常; 在js中Math.round();不支持小数; js .toFixed();并是银行家舍入法;不是四舍五入;可以看一下源码; toFixed \*\*定點(Fixed Point)表示法\*\* 官方也没说过toFixed()是四舍五入; !\[\](https://raw.githubusercontent.com/yan-bolan/picbed/master/img/picgo/20220928211826.png) \[ECMAScript® 2023 Language Specification (tc39.es)\](https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-number.prototype.tofixed) 源代码; !\[\](https://raw.githubusercontent.com/yan-bolan/picbed/master/img/picgo/20220928212348.png) !\[\](https://raw.githubusercontent.com/yan-bolan/picbed/master/img/picgo/20220928211309.png) !\[\](https://raw.githubusercontent.com/yan-bolan/picbed/master/img/picgo/20220928211413.png) # 财务和货币计算 浮点数:运算会产生误差; 在CSharp中: 使用decimal:\[浮点数值类型 - C# 引用 \| Microsoft Learn\](https://learn.microsoft.com/zh-cn/dotnet/csharp/language-reference/builtin-types/floating-point-numeric-types) 当所需的精度由小数点右侧的位数决定时,\`decimal\` 类型是合适的。 在财务中,通常就是只取几位小数; \> 此类数字通常用于财务应用程序、货币金额(例如 $1.00)、利率(例如 2.625%)等。 精确到只有一个小数的偶数用 \`decimal\` 类型处理会更准确:例如,0.1 可以由 \`decimal\` 实例精确表示,而没有精确表示 0.1 的 \`double\` 或 \`float\` 实例。 由于数值类型存在这种差异,因此当你对十进制数据使用 \`double\` 或 \`float\` 时,算术计算可能会出现意外的舍入错误。 \`只有被坑过才知道decimal 货币的重要性\` js中并没有提供这个类型;