Dart int floorToDouble()
Syntax & Examples
int.floorToDouble() method
The `floorToDouble` method in Dart returns this converted to a double.
Syntax of int.floorToDouble()
The syntax of int.floorToDouble() method is:
double floorToDouble()
This floorToDouble() method of int returns this.toDouble().
Return Type
int.floorToDouble() returns value of type double
.
✐ Examples
1 Floor to double of an integer
In this example,
- We create an integer variable
num
with the value 4. - We use the
floorToDouble()
method to convert it to a double. - We then print the result to standard output.
Dart Program
void main() {
int num = 4;
double floorDouble = num.floorToDouble();
print('Floor to double of $num: $floorDouble');
}
Output
Floor to double of 4: 4
2 Floor to double of a negative integer
In this example,
- We create an integer variable
negativeNum
with the value -3. - We use the
floorToDouble()
method to convert it to a double. - We then print the result to standard output.
Dart Program
void main() {
int negativeNum = -3;
double floorDoubleNegative = negativeNum.floorToDouble();
print('Floor to double of $negativeNum: $floorDoubleNegative');
}
Output
Floor to double of -3: -3
3 Floor to double of an integer
In this example,
- We create an integer variable
integerNum
with the value 7. - We use the
floorToDouble()
method to convert it to a double. - We then print the result to standard output.
Dart Program
void main() {
int integerNum = 7;
double floorDoubleInteger = integerNum.floorToDouble();
print('Floor to double of $integerNum: $floorDoubleInteger');
}
Output
Floor to double of 7: 7
Summary
In this Dart tutorial, we learned about floorToDouble() method of int: the syntax and few working examples with output and detailed explanation for each example.