NumberFormatter.swift 607 B

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