diff --git a/TelegramCore/StringFormat.swift b/TelegramCore/StringFormat.swift index 0165737708..3b58878fcd 100644 --- a/TelegramCore/StringFormat.swift +++ b/TelegramCore/StringFormat.swift @@ -1,26 +1,26 @@ -public func dataSizeString(_ size: Int, forceDecimal: Bool = false) -> String { - return dataSizeString(Int64(size), forceDecimal: forceDecimal) +public func dataSizeString(_ size: Int, forceDecimal: Bool = false, decimalSeparator: String = ".") -> String { + return dataSizeString(Int64(size), forceDecimal: forceDecimal, decimalSeparator: decimalSeparator) } -public func dataSizeString(_ size: Int64, forceDecimal: Bool = false) -> String { +public func dataSizeString(_ size: Int64, forceDecimal: Bool = false, decimalSeparator: String = ".") -> String { if size >= 1024 * 1024 * 1024 { - let remainder = (size % (1024 * 1024 * 1024)) / (1024 * 1024 * 102) + let remainder = Int64((Double(size % (1024 * 1024 * 1024)) / (1024 * 1024 * 102.4)).rounded(.down)) if remainder != 0 || forceDecimal { - return "\(size / (1024 * 1024 * 1024)),\(remainder) GB" + return "\(size / (1024 * 1024 * 1024))\(decimalSeparator)\(remainder) GB" } else { return "\(size / (1024 * 1024 * 1024)) GB" } } else if size >= 1024 * 1024 { - let remainder = (size % (1024 * 1024)) / (1024 * 102) + let remainder = Int64((Double(size % (1024 * 1024)) / (1024.0 * 102.4)).rounded(.down)) if remainder != 0 || forceDecimal { - return "\(size / (1024 * 1024)),\(remainder) MB" + return "\(size / (1024 * 1024))\(decimalSeparator)\(remainder) MB" } else { return "\(size / (1024 * 1024)) MB" } } else if size >= 1024 { let remainder = (size % (1024)) / (102) if remainder != 0 || forceDecimal { - return "\(size / 1024),\(remainder) KB" + return "\(size / 1024)\(decimalSeparator)\(remainder) KB" } else { return "\(size / 1024) KB" }