Search code examples
flutterdartflutter-testdart-pubdart-null-safety

flutter problem : How to convert this type of double from string?


I want to convert sting to double , here my double is saperated by comma, So how to do it?

void main() {
  var myInt = int.parse('12345');
  assert(myInt is int);
  print(myInt); // 12345
  print(myInt.runtimeType);  // int
  
  
    var myDouble = double.parse('1,230.45');
  assert(myInt is double);
  print(myDouble); 
  print(myDouble.runtimeType); // double
}

enter image description here


Solution

  • You need to remove , first to parse it as double:

    var myDouble = double.parse('1,230.45'.replaceAll(',', ''));