spb/vrai-prix-ios Public
App iOS native de Vrai-Prix — estimation immobilière transparente pour le Québec (SwiftUI, MapKit, Swift Charts)
Swift 100%
1// Auteur : Simon-Pierre Boucher — contact@spboucher.ai2// Formatage à la québécoise : dollars CAD fr_CA, m², distances.3import Foundation45enum Fmt {6 private static let cadFormatter: NumberFormatter = {7 let f = NumberFormatter()8 f.numberStyle = .currency9 f.locale = Locale(identifier: "fr_CA")10 f.maximumFractionDigits = 011 return f12 }()1314 private static let numFormatter: NumberFormatter = {15 let f = NumberFormatter()16 f.numberStyle = .decimal17 f.locale = Locale(identifier: "fr_CA")18 f.maximumFractionDigits = 019 return f20 }()2122 /// « 833 800 $ »23 static func cad(_ value: Double?) -> String {24 guard let value, value.isFinite else { return "—" }25 return cadFormatter.string(from: NSNumber(value: value.rounded())) ?? "—"26 }2728 /// « +34 000 $ » / « −83 700 $ » — ajustements du moteur, signe explicite.29 static func signedCad(_ value: Double) -> String {30 let s = cad(abs(value))31 if abs(value) < 0.5 { return "±0 $" }32 return (value >= 0 ? "+" : "−") + s33 }3435 /// « 195 m² »36 static func m2(_ value: Double?) -> String {37 guard let value, value.isFinite else { return "—" }38 return (numFormatter.string(from: NSNumber(value: value.rounded())) ?? "—") + " m²"39 }4041 static func num(_ value: Double?) -> String {42 guard let value, value.isFinite else { return "—" }43 return numFormatter.string(from: NSNumber(value: value.rounded())) ?? "—"44 }4546 /// « 850 m » ou « 2,4 km »47 static func distance(_ meters: Double) -> String {48 if meters < 1000 { return "\(Int(meters.rounded())) m" }49 return String(format: "%.1f km", locale: Locale(identifier: "fr_CA"), meters / 1000)50 }5152 /// « 2026-04 » → « avril 2026 »53 static func monthYear(_ isoDate: String) -> String {54 let input = DateFormatter()55 input.dateFormat = "yyyy-MM-dd"56 input.locale = Locale(identifier: "en_US_POSIX")57 guard let d = input.date(from: isoDate) else { return isoDate }58 let output = DateFormatter()59 output.dateFormat = "MMMM yyyy"60 output.locale = Locale(identifier: "fr_CA")61 return output.string(from: d)62 }6364 /// « 12,3 % »65 static func pct(_ value: Double?, decimals: Int = 1) -> String {66 guard let value, value.isFinite else { return "—" }67 return String(format: "%.\(decimals)f %%", locale: Locale(identifier: "fr_CA"), value)68 }69}70