Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/friendlyu/friendlynumbers
Making numbers friendlier.
https://github.com/friendlyu/friendlynumbers
hacktoberfest ios numbers numbers-to-words swift swift-3 swift-language swift3
Last synced: 2 months ago
JSON representation
Making numbers friendlier.
- Host: GitHub
- URL: https://github.com/friendlyu/friendlynumbers
- Owner: FriendlyU
- License: mit
- Created: 2017-06-08T03:57:45.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-31T12:42:17.000Z (about 6 years ago)
- Last Synced: 2024-10-12T14:42:18.944Z (2 months ago)
- Topics: hacktoberfest, ios, numbers, numbers-to-words, swift, swift-3, swift-language, swift3
- Language: Swift
- Size: 10.7 KB
- Stars: 6
- Watchers: 3
- Forks: 7
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.MD
Awesome Lists containing this project
README
# FriendlyNumbers
Converts numbers like 1000 to 1K and 1500 to 1.5K.
This representation of numbers using K (thousand), M (million), and B (billion) is commonly used in banking and games universe to simplify the reading of a big number.
## Installation
FriendlyNumbers is available through [CocoaPods](http://cocoapods.org).
To install it, simply add the following line to your Podfile:
```ruby
pod 'FriendlyNumbers'
```## Usage
There are two different features available. `FNSimple` and `FNMostSimple`. Both can be used directly onto an integer.
`FNSimple` rounds numbers to the nearest tenths place whereas `FNMostSimple` rounds numbers to the nearest whole number.
## Examples
```swift
let number = 1530
print(number.FNMostSimple) // prints 1Klet number = 1530
print(number.FNSimple) // prints 1.5Klet number = 15320
print(number.FNMostSimple) // prints 15Klet number = 15320
print(number.FNSimple) // prints 15.3Klet number = 153200
print(number.FNMostSimple) // prints 153Klet number = 153200
print(number.FNSimple) // prints 153.2Klet number = 1532200
print(number.FNMostSimple) // prints 1Mlet number = 1532200
print(number.FNSimple) // prints 1.5Mlet number = 15300000
print(number.FNMostSimple) // prints 15Mlet number = 15300000
print(number.FNSimple) // prints 15.3M
```