Last active
April 13, 2019 08:04
-
-
Save muhlenXi/db2d16f7296085ad191c48924561a1d3 to your computer and use it in GitHub Desktop.
金额分 数字格式化 如 4132 --> 4,132.00
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 金额分 数字格式化 如 4132 --> 4,132.00 | |
func decimalFormatterValue(value: Int) -> String? { | |
let decimal = value % 100 | |
let nonDecimal = value / 100 | |
let formatter = NumberFormatter.init() | |
formatter.numberStyle = .decimal | |
if let title = formatter.string(from: NSNumber.init(value: nonDecimal)) { | |
return title + String.init(format: ".%02d", decimal) | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment