I want to covert a String to currency and keep 2 decimal spaces:
let formatter = NumberFormatter()
formatter.maximumFractionDigits = 2
formatter.numberStyle = .currency
formatter.locale = Locale(identifier: "zh_CN")
formatter.number(from: "¥12") // Output 12 correct.
formatter.number(from: "¥1213.1263") // Output 1213.1263
formatter.string(from: 1213.1263) // Output "¥1,213.13"
You can see the output in comments. Why not the formatter.number(from: "¥1213.1263") output 1213.13? I have set the max fraction digits is 2.