在Swift中从String转换为Decimal时,将删除十进制值

问题描述 投票:-1回答:2

请检查此示例

 let strValue = "12.00"
 let decimalValue = Decimal(string: strValue) // 12

它总是返回12而不是12.00我也尝试使用NSNumberFloatDouble,但它总是删除零。

您能先谢谢我吗?>

请检查此示例let strValue =“ 12.00” let decimalValue = Decimal(string:strValue)// 12总是返回12而不是12.00我也尝试使用NSNumber,Float和Double,但总是这样...

ios swift string swift3 nsdecimalnumber
2个回答
3
投票

像马丁说。 12和12.00是相同的数字。在逗号后面有多少个0并不重要。


1
投票

1212.00之间没有区别。我们唯一需要的是将值提供给user。,因为您可以使用格式化的字符串。

© www.soinside.com 2019 - 2024. All rights reserved.