Dart double toString()
Syntax & Examples

double.toString() method

The `toString` method provides a string representation of the given double value.


Syntax of double.toString()

The syntax of double.toString() method is:

 String toString() 

This toString() method of double provide a representation of this double value.

Return Type

double.toString() returns value of type String.



✐ Examples

1 Convert a positive double to string

In this example,

  1. We define a double num with a value of 3.14.
  2. We call the toString() method on num to get its string representation.
  3. We print the result to standard output.

Dart Program

void main() {
  double num = 3.14;
  String str = num.toString();
  print('String representation of 3.14: $str');
}

Output

String representation of 3.14: 3.14

2 Convert a negative double to string

In this example,

  1. We define a double num with a value of -5.6.
  2. We call the toString() method on num to get its string representation.
  3. We print the result to standard output.

Dart Program

void main() {
  double num = -5.6;
  String str = num.toString();
  print('String representation of -5.6: $str');
}

Output

String representation of -5.6: -5.6

3 Convert an integer double to string

In this example,

  1. We define a double num with a value of 10.0.
  2. We call the toString() method on num to get its string representation.
  3. We print the result to standard output.

Dart Program

void main() {
  double num = 10.0;
  String str = num.toString();
  print('String representation of 10.0: $str');
}

Output

String representation of 10.0: 10

Summary

In this Dart tutorial, we learned about toString() method of double: the syntax and few working examples with output and detailed explanation for each example.