I am using this image extension to calculate the image size in MB. And I am getting the size of my image with a comma(,) instead of a dot(.) like "1,7 MB"
extension UIImage {
func getFileSizeInfo(allowedUnits: ByteCountFormatter.Units = .useMB,
countStyle: ByteCountFormatter.CountStyle = .file) -> String? {
let formatter = ByteCountFormatter()
formatter.allowedUnits = allowedUnits
formatter.countStyle = countStyle
return getSizeInfo(formatter: formatter)
}
func getSizeInfo(formatter: ByteCountFormatter, compressionQuality: CGFloat = 1.0) -> String? {
guard let imageData = jpegData(compressionQuality: compressionQuality) else { return nil }
return formatter.string(fromByteCount: Int64(imageData.count))
}
}
Method calling:
var imageSizeInMB = image.getFileSizeInfo()
print(imageSizeInMB) //Output "1,7 MB"
I need output like "1.7 MB"
I am not looking for "replace characters in a string".
Please help me here.