I tried double.parse to get the data of TextFormField as a double:
double _pointsUsing = double.parse(pointsEdditingController.text);
but it causes error saying "The method '>=' was called on null". If I tried this:
double _pointsUsing = double.tryParse(pointsEdditingController.text);
it returns null.
The textformfield text value is: 1,133.00
It also says "Tried calling: <(1133.0) 1,133.00"
CodePudding user response:
you need to remove "," from the string then after parse to double.
double _pointsUsing = double.parse(pointsEdditingController.text.replaceAll(",",""));
CodePudding user response:
You can do this way :
print( double.tryParse('2,456.90'.replaceAll(",","")));
CodePudding user response:
Use keyboard type as number in text field it may help you
TextField(
decoration: new InputDecoration(
labelText: "Enter your number"),
keyboardType: TextInputType.number,
);
```
Then parse your data like this:-
String textFieldData = pointsEdditingController.text.isEmpty ? "0" : pointsEdditingController.text;
double _pointsUsing = double.parse(textFieldData);
