mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
Various fixes
This commit is contained in:
@@ -10,7 +10,7 @@ public func formatTonAddress(_ address: String) -> String {
|
||||
return address
|
||||
}
|
||||
|
||||
public func formatTonUsdValue(_ value: Int64, divide: Bool = true, rate: Double, dateTimeFormat: PresentationDateTimeFormat) -> String {
|
||||
public func formatTonUsdValue(_ value: Int64, divide: Bool = true, rate: Double = 1.0, dateTimeFormat: PresentationDateTimeFormat) -> String {
|
||||
let decimalSeparator = dateTimeFormat.decimalSeparator
|
||||
let normalizedValue: Double = divide ? Double(value) / 1000000000 : Double(value)
|
||||
var formattedValue = String(format: "%0.2f", normalizedValue * rate)
|
||||
@@ -27,15 +27,15 @@ public func formatTonUsdValue(_ value: Int64, divide: Bool = true, rate: Double,
|
||||
return "$\(formattedValue)"
|
||||
}
|
||||
|
||||
public func formatTonAmountText(_ value: Int64, decimalSeparator: String, showPlus: Bool = false) -> String {
|
||||
public func formatTonAmountText(_ value: Int64, dateTimeFormat: PresentationDateTimeFormat, showPlus: Bool = false) -> String {
|
||||
var balanceText = "\(abs(value))"
|
||||
while balanceText.count < 10 {
|
||||
balanceText.insert("0", at: balanceText.startIndex)
|
||||
}
|
||||
balanceText.insert(contentsOf: decimalSeparator, at: balanceText.index(balanceText.endIndex, offsetBy: -9))
|
||||
balanceText.insert(contentsOf: dateTimeFormat.decimalSeparator, at: balanceText.index(balanceText.endIndex, offsetBy: -9))
|
||||
while true {
|
||||
if balanceText.hasSuffix("0") {
|
||||
if balanceText.hasSuffix("\(decimalSeparator)0") {
|
||||
if balanceText.hasSuffix("\(dateTimeFormat.decimalSeparator)0") {
|
||||
balanceText.removeLast()
|
||||
balanceText.removeLast()
|
||||
break
|
||||
@@ -52,8 +52,18 @@ public func formatTonAmountText(_ value: Int64, decimalSeparator: String, showPl
|
||||
balanceText.insert("+", at: balanceText.startIndex)
|
||||
}
|
||||
|
||||
if let dec = balanceText.range(of: decimalSeparator) {
|
||||
balanceText = String(balanceText[balanceText.startIndex ..< min(balanceText.endIndex, balanceText.index(dec.upperBound, offsetBy: 2))])
|
||||
if let dotIndex = balanceText.range(of: dateTimeFormat.decimalSeparator) {
|
||||
balanceText = String(balanceText[balanceText.startIndex ..< min(balanceText.endIndex, balanceText.index(dotIndex.upperBound, offsetBy: 2))])
|
||||
|
||||
let integerPartString = balanceText[..<dotIndex.lowerBound]
|
||||
if let integerPart = Int32(integerPartString) {
|
||||
let modifiedIntegerPart = presentationStringsFormattedNumber(integerPart, dateTimeFormat.groupingSeparator)
|
||||
|
||||
let resultString = "\(modifiedIntegerPart)\(balanceText[dotIndex.lowerBound...])"
|
||||
return resultString
|
||||
}
|
||||
} else if let integerPart = Int32(balanceText) {
|
||||
balanceText = presentationStringsFormattedNumber(integerPart, dateTimeFormat.groupingSeparator)
|
||||
}
|
||||
|
||||
return balanceText
|
||||
|
||||
Reference in New Issue
Block a user