Skip to content

Instantly share code, notes, and snippets.

@muhlenXi
Last active April 13, 2019 08:04
Show Gist options
  • Save muhlenXi/db2d16f7296085ad191c48924561a1d3 to your computer and use it in GitHub Desktop.
Save muhlenXi/db2d16f7296085ad191c48924561a1d3 to your computer and use it in GitHub Desktop.
金额分 数字格式化 如 4132 --> 4,132.00
/// 金额分 数字格式化 如 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