mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 14:45:21 +00:00
Rename TelegramCore source folder
This commit is contained in:
30
submodules/TelegramCore/Sources/StringFormat.swift
Normal file
30
submodules/TelegramCore/Sources/StringFormat.swift
Normal file
@@ -0,0 +1,30 @@
|
||||
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, decimalSeparator: String = ".") -> String {
|
||||
if size >= 1024 * 1024 * 1024 {
|
||||
let remainder = Int64((Double(size % (1024 * 1024 * 1024)) / (1024 * 1024 * 102.4)).rounded(.down))
|
||||
if remainder != 0 || forceDecimal {
|
||||
return "\(size / (1024 * 1024 * 1024))\(decimalSeparator)\(remainder) GB"
|
||||
} else {
|
||||
return "\(size / (1024 * 1024 * 1024)) GB"
|
||||
}
|
||||
} else if size >= 1024 * 1024 {
|
||||
let remainder = Int64((Double(size % (1024 * 1024)) / (1024.0 * 102.4)).rounded(.down))
|
||||
if remainder != 0 || forceDecimal {
|
||||
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)\(decimalSeparator)\(remainder) KB"
|
||||
} else {
|
||||
return "\(size / 1024) KB"
|
||||
}
|
||||
} else {
|
||||
return "\(size) B"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user