Swiftpack.co - RuiCarneiro/SwiftEngineeringNumberFormatter as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by RuiCarneiro.
RuiCarneiro/SwiftEngineeringNumberFormatter 1.1.0
Number formatter using the engineering notation for Swift
⭐️ 1
🕓 3 weeks ago
.package(url: "https://github.com/RuiCarneiro/SwiftEngineeringNumberFormatter.git", from: "1.1.0")

SwiftEngineeringNumberFormatter

Number formatter using the engineering notation. All multiple of 3 SI metric prefixes are supported.

Basic Use

import SwiftEngineeringNumberFormatter

// Instantiate the class:
let enf = EngineeringNumberFormatter()

// Convert String to Double?
enf.double("10k")                      // returns 10E3
enf.double(":P")                       // returns nil

// Convert Double to String
enf.string(123E-6)                     // returns "123µ"

// Use "u" instead of "µ"
enf.useGreekMu = false
enf.string(123E-6)                     // returns "123u"

// Set the number of decimal places
enf.maximumFractionDigits = 1
enf.string(1.0 / 3.0)                  // returns "333.3m"

enf.maximumFractionDigits = 0
enf.string(2999)                       // returns "3k"

// You can also instantiate Doubles
Double(engineeringNotation: "33p")     // returns 33E-12

Add to your Swift Package Manager Project

See an example here.

Add package dependencies:

.package(url: "https://github.com/RuiCarneiro/SwiftEngineeringNumberFormatter", from: "1.1.0")

And to your target, the dependency:

.product(name: "SwiftEngineeringNumberFormatter", package: "SwiftEngineeringNumberFormatter")

Copyright and License

(C) Rui Carneiro

Licensed under Apache License 2.0

GitHub

link
Stars: 1
Last commit: 5 days ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

1.1.0
3 weeks ago
  • Extension for instancing Double from an engineering notation String
  • Fix for NaN, Infinite values

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics