The `toString` method in Dart returns a string representation of this integer.
The syntax of int.toString() method is:
String toString()
This toString() method of int returns a string representation of this integer.
int.toString() returns value of type String
.
In this example,
num
with the value 123.toString()
method to convert it to a string.void main() {
int num = 123;
String numString = num.toString();
print('String representation of $num: $numString');
}
String representation of 123: 123
In this example,
negativeNum
with the value -456.toString()
method to convert it to a string.void main() {
int negativeNum = -456;
String negativeString = negativeNum.toString();
print('String representation of $negativeNum: $negativeString');
}
String representation of -456: -456
In this example,
zero
with the value 0.toString()
method to convert it to a string.void main() {
int zero = 0;
String zeroString = zero.toString();
print('String representation of $zero: $zeroString');
}
String representation of 0: 0
In this Dart tutorial, we learned about toString() method of int: the syntax and few working examples with output and detailed explanation for each example.