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

@ -26,6 +26,9 @@ public func presentationStringsFormattedNumber(_ count: Int32, _ groupingSeparat
let string = "\(count)" let string = "\(count)"
if groupingSeparator.isEmpty || abs(count) < 1000 { if groupingSeparator.isEmpty || abs(count) < 1000 {
return string return string
} else {
if count < 0 {
return "-\(presentationStringsFormattedNumber(abs(count), groupingSeparator))"
} else { } else {
var groupedString: String = "" var groupedString: String = ""
for i in 0 ..< Int(ceil(Double(string.count) / 3.0)) { for i in 0 ..< Int(ceil(Double(string.count) / 3.0)) {
@ -38,6 +41,7 @@ public func presentationStringsFormattedNumber(_ count: Int32, _ groupingSeparat
return groupedString return groupedString
} }
} }
}
public func presentationStringsFormattedNumber(_ starsAmount: StarsAmount, _ groupingSeparator: String = "") -> String { public func presentationStringsFormattedNumber(_ starsAmount: StarsAmount, _ groupingSeparator: String = "") -> String {
if starsAmount.nanos == 0 { if starsAmount.nanos == 0 {