Dart int truncateToDouble()
Syntax & Examples
int.truncateToDouble() method
The `truncateToDouble` method in Dart returns the double representation of this integer.
Syntax of int.truncateToDouble()
The syntax of int.truncateToDouble() method is:
double truncateToDouble()
This truncateToDouble() method of int returns this.toDouble().
Return Type
int.truncateToDouble() returns value of type double
.
✐ Examples
1 Convert an integer to double
In this example,
- We assign the value
5
to the integer variablenum1
. - We convert
num1
to a double using thetruncateToDouble()
method. - We print the result to standard output.
Dart Program
void main() {
int num1 = 5;
double doubleNum1 = num1.truncateToDouble();
print('Double value of $num1: $doubleNum1');
}
Output
Double value of 5: 5
2 Convert a negative integer to double
In this example,
- We assign the value
-3
to the integer variablenum2
. - We convert
num2
to a double using thetruncateToDouble()
method. - We print the result to standard output.
Dart Program
void main() {
int num2 = -3;
double doubleNum2 = num2.truncateToDouble();
print('Double value of $num2: $doubleNum2');
}
Output
Double value of -3: -3
3 Convert a positive integer to double
In this example,
- We assign the value
10
to the integer variablenum3
. - We convert
num3
to a double using thetruncateToDouble()
method. - We print the result to standard output.
Dart Program
void main() {
int num3 = 10;
double doubleNum3 = num3.truncateToDouble();
print('Double value of $num3: $doubleNum3');
}
Output
Double value of 10: 10
Summary
In this Dart tutorial, we learned about truncateToDouble() method of int: the syntax and few working examples with output and detailed explanation for each example.