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