NumberFormatter.swift 648 B

123456789101112131415161718192021222324
  1. //
  2. // NumberFormatter.swift
  3. // OmniKitUI
  4. //
  5. // Created by Pete Schwamb on 3/19/23.
  6. // Copyright © 2023 LoopKit Authors. All rights reserved.
  7. //
  8. import Foundation
  9. extension NumberFormatter {
  10. func decibleString(from decibles: Int?) -> String? {
  11. if let decibles = decibles, let formatted = string(from: NSNumber(value: decibles)) {
  12. return String(format: LocalizedString("%@ dB", comment: "Unit format string for an RSSI value in decibles"), formatted)
  13. } else {
  14. return nil
  15. }
  16. }
  17. func string(from number: Double) -> String? {
  18. return string(from: NSNumber(value: number))
  19. }
  20. }