mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
Various improvements
This commit is contained in:
@@ -35,3 +35,28 @@ class ScalesNumberFormatter: NumberFormatter {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TonNumberFormatter: NumberFormatter {
|
||||
override func string(from number: NSNumber) -> String? {
|
||||
var balanceText = "\(number.intValue)"
|
||||
let decimalSeparator = self.decimalSeparator ?? "."
|
||||
while balanceText.count < 10 {
|
||||
balanceText.insert("0", at: balanceText.startIndex)
|
||||
}
|
||||
balanceText.insert(contentsOf: decimalSeparator, at: balanceText.index(balanceText.endIndex, offsetBy: -9))
|
||||
while true {
|
||||
if balanceText.hasSuffix("0") {
|
||||
if balanceText.hasSuffix("\(decimalSeparator)0") {
|
||||
balanceText.removeLast()
|
||||
balanceText.removeLast()
|
||||
break
|
||||
} else {
|
||||
balanceText.removeLast()
|
||||
}
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
return balanceText
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user