Fix negative number formatting

This commit is contained in:
Ilya Laktyushin 2025-04-08 20:07:07 +04:00
parent 2ab4af656b
commit 732a430119

View File

@ -27,15 +27,19 @@ public func presentationStringsFormattedNumber(_ count: Int32, _ groupingSeparat
if groupingSeparator.isEmpty || abs(count) < 1000 { if groupingSeparator.isEmpty || abs(count) < 1000 {
return string return string
} else { } else {
var groupedString: String = "" if count < 0 {
for i in 0 ..< Int(ceil(Double(string.count) / 3.0)) { return "-\(presentationStringsFormattedNumber(abs(count), groupingSeparator))"
let index = string.count - Int(i + 1) * 3 } else {
if !groupedString.isEmpty { var groupedString: String = ""
groupedString = groupingSeparator + groupedString for i in 0 ..< Int(ceil(Double(string.count) / 3.0)) {
let index = string.count - Int(i + 1) * 3
if !groupedString.isEmpty {
groupedString = groupingSeparator + groupedString
}
groupedString = String(string[string.index(string.startIndex, offsetBy: max(0, index)) ..< string.index(string.startIndex, offsetBy: index + 3)]) + groupedString
} }
groupedString = String(string[string.index(string.startIndex, offsetBy: max(0, index)) ..< string.index(string.startIndex, offsetBy: index + 3)]) + groupedString return groupedString
} }
return groupedString
} }
} }