Skip to content

Commit

Permalink
Merge pull request #10 from youjinp/develop
Browse files Browse the repository at this point in the history
Fix #9
  • Loading branch information
youjinp authored Sep 6, 2020
2 parents c36f11e + 572d0f4 commit c253a9f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Sources/SwiftUIKit/views/CurrencyTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,16 @@ public struct CurrencyTextField: UIViewRepresentable {
if self.value == nil {
textField.text = nil
} else {
textField.text = Formatter.currency.string(from: NSNumber(value: self.value!))
// format to 2 decimal places if there's fractions
let formatter = Formatter.currency
var integer = 0.0
let fraction = modf(self.value!, &integer)
if fraction > 0 {
formatter.maximumFractionDigits = 2
} else {
formatter.maximumFractionDigits = 0
}
textField.text = formatter.string(from: NSNumber(value: self.value!))
}
}

Expand Down

0 comments on commit c253a9f

Please sign in to comment.