Search code examples
dartdouble

How can I convert String with comma to double in Dart?


I have a text field in which I am taking string as input and converting it to double using double.parse() method.

I am using the number type keyboard for the textfield. But when the user inputs a comma with numbers for example 5,000 my program is giving output of 5.00

How can I get the output of 5000 from 5,000 in dart?


Solution

  • For the answer to your final question:

    String t = '5,000';
    double f = double.parse(t.replaceAll(',',''));
    print(f);
    

    Use .replaceAll() to replace all instances of the comma with no character