skip to Main Content

I want to Know the difference between todoudle and double.parse in dart and where are each of them used?

The result of both is the same, but the difference may be in the compilation

2

Answers


  1. You can only use toDouble function when type of variable is int, double or num. If you have dynamic variable, you don’t know exactly type, you want to convert to double, you can use double.parse() or double.tryParse()

    Login or Signup to reply.
  2. double.parse is used to convert a string to a double.
    Example:

    String value= "3.54";
    double newValue= double.parse(value);
    

    toDouble is used to convert a numeric value of another data type to a double.

    int value= 3;
    double newValue= value.toDouble();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search