Skip to content

Commit

Permalink
Merge pull request #128 from vergecurrency/maximum-fraction-digits
Browse files Browse the repository at this point in the history
Restrict the maximum of fraction digits 🧩
  • Loading branch information
marpme authored Feb 10, 2019
2 parents dc4c030 + 329f748 commit a6a3bbc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions VergeiOS/Components/UI/Inputs/CurrencyInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CurrencyInput: UITextField {
fileprivate let formatter: NumberFormatter = {
let formatter = NumberFormatter()
formatter.numberStyle = .currency
formatter.maximumFractionDigits = 8
formatter.maximumFractionDigits = Constants.maximumFractionDigits

return formatter
}()
Expand Down Expand Up @@ -54,7 +54,7 @@ class CurrencyInput: UITextField {
}

public func setAmount(_ amount: NSNumber) {
text = amount.toBlankCurrency(fractDigits: 8)
text = amount.toBlankCurrency(fractDigits: Constants.maximumFractionDigits)

format()
}
Expand Down
2 changes: 1 addition & 1 deletion VergeiOS/Extensions/NSNumber+Currency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ extension NSNumber {
var fractDigits = fractDigits

if fractDigits == nil {
fractDigits = 8
fractDigits = Constants.maximumFractionDigits

if self.doubleValue > 99 {
fractDigits = 6
Expand Down
5 changes: 5 additions & 0 deletions VergeiOS/Utils/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public struct Constants {
* Confirmations needed to change the UI.
*/
public static let confirmationsNeeded: Int = 1

/**
* The maximum of digits.
*/
public static let maximumFractionDigits: Int = 6


/**
Expand Down

0 comments on commit a6a3bbc

Please sign in to comment.