NSDecimalNumber 使用股票 NumberFormatter 丢失精度

问题描述

var stringForServer: String?{
        let numberFormatter = NumberFormatter()
        numberFormatter.locale = ru_ru_posix
        numberFormatter.numberStyle = .decimal
    numberFormatter.groupingSeparator = "" // kill space
   // it is invalid to lose precision in this converter. do not.            numberFormatter.maximumFractionDigits = 2
        let stringValue = numberFormatter.string(from: self)
        print ("conversion NSDecimalNumber \(self) -> \(stringValue)")
        return stringValue
}

我有 2.5038,结果是“2.504” 如您所见,maximumFractionDigits 未在任何地方设置。 有什么办法可以摆脱这种困境?我虽然十进制失去精度 而 NSDecimalNumber 传统上没有(是的,那是讽刺)

iphone8 模拟器 14.4 xcode 12.4

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)