Skip to content

Commit

Permalink
use numberFormatter for international users
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Hao committed Jun 20, 2021
1 parent 69b1c90 commit 3b77243
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
region = "VN"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
12 changes: 11 additions & 1 deletion Sources/ObjectForm/view/TypedInputCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public class TypedInputCell<T>: FormInputCell, UITextFieldDelegate {
return dateFormatter
}()

private var numberFormatter: NumberFormatter = {
let formatter = NumberFormatter()
formatter.maximumFractionDigits = 5
return formatter
}()

override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)

Expand All @@ -41,7 +47,7 @@ public class TypedInputCell<T>: FormInputCell, UITextFieldDelegate {
case is String.Type:
return text
case is Double.Type:
return Double(text) ?? Double(0)
return (numberFormatter.number(from: text) ?? 0).doubleValue
case is Date.Type:
return dateFormatter.date(from: text)
default:
Expand Down Expand Up @@ -92,8 +98,12 @@ public class TypedInputCell<T>: FormInputCell, UITextFieldDelegate {
if let number = row.baseValue as? Double, number < Double.ulpOfOne {
// clear the text so that user can start input from integer value
textField.text = ""
} else if let double = row.baseValue as? Double {
textField.text = numberFormatter.string(from: double as NSNumber)

} else if let date = row.baseValue as? Date {
textField.text = dateFormatter.string(from: date)

} else {
textField.text = row.description
}
Expand Down

0 comments on commit 3b77243

Please sign in to comment.