mirror of
https://github.com/VernissageApp/Vernissage.git
synced 2024-12-29 02:10:44 +01:00
28 lines
672 B
Swift
28 lines
672 B
Swift
//
|
|
// https://mczachurski.dev
|
|
// Copyright © 2023 Marcin Czachurski and the repository contributors.
|
|
// Licensed under the MIT License.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
extension String {
|
|
func calculateExifNumber() -> String? {
|
|
guard self.contains("/") else {
|
|
return self
|
|
}
|
|
|
|
let parts = self.split(separator: "/")
|
|
guard parts.count == 2 else {
|
|
return nil
|
|
}
|
|
|
|
if let first = Int(parts[0]), let second = Int(parts[1]) {
|
|
let calculated = Double(first) / Double(second)
|
|
return String(calculated.rounded(toPlaces: 2))
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|