swift - 用于 Greate 操作的 Swift stdlib 默认实现
问题描述
extension Decimal: LCDecimalPrecise {
public static func == (lhs: Decimal, rhs: Decimal) -> Bool {
return !((lhs - rhs).doubleValue > LCMetricUnit.moneyPrecise ||
(rhs - lhs).doubleValue > LCMetricUnit.moneyPrecise)
}
public static func < (lhs: Decimal, rhs: Decimal) -> Bool {
return (lhs - rhs).doubleValue < -LCMetricUnit.moneyPrecise
}
public static func > (lhs: Decimal, rhs: Decimal) -> Bool {
return (lhs - rhs).doubleValue > LCMetricUnit.moneyPrecise
}
}
覆盖前两个方法后(>忽略运算符方法),然后调用以下方法,例如:
if Decimal(string: "1") > Decimal(string: "2") {//TODO sth}
我认为 less(<) 运算符将期望根据文档和源代码被调用,
调试时,它不会被调用。这么奇怪!!!最后,我们实施更大的操作来解决这个问题。
解决方案
推荐阅读
- angular - 在角度材料工具栏中放置主页链接
- java - 线程“restartedMain”中的异常 java.lang.reflect.InvocationTargetException
- javascript - 从每个页面加载调用 javascript 函数,而不在其他 html 页面中进行任何更改
- python - Beam / Dataflow 自定义 Python 作业 - 云存储到 PubSub
- android - 我使用 fcm 向设备发送通知,但收不到通知
- amazon-web-services - 使用系统管理器运行命令在 AWS 上的 maven artifactory 下载并安装 exe 文件
- exception - 我在使用 PHP 7.2 的条件下在 Cakephp 2.5 中抛出异常,它什么也没抛出,为什么?
- sql - 为什么我在这里得到 System.Data.DataRow?
- python - Python 找不到已安装的模块
- php - 为什么要更改我的网站的加载时间?