There are various methods provided by dart, using that we can convert double to an integer.

Here i mentioned methods with description.

1. truncate():

  • Method: truncate()
  • Description: This method returns the integer value closest to but no greater in magnitude than the double value. It effectively removes the fractional part of the number without rounding.

2. toInt():

  • Method: toInt()
  • Description: Converts the double to an integer by discarding the fractional part. This method rounds towards zero.
    There are no difference between toInt() and truncate() method.

3. round():

  • Method: round()
  • Description: Rounds a number to the nearest integer. If the fractional part is 0.5 or higher, it rounds up; otherwise, it rounds down.

4. ceil():

  • Method: ceil()
  • Description: Rounds a number up to the nearest integer. If the number is already an integer, it remains unchanged. For positive numbers, it rounds up; for negative numbers, it rounds towards zero.

5. floor():

  • Method: floor()
  • Description: Rounds a number down to the nearest integer. It always rounds towards negative infinity, regardless of the number’s sign.

Example

Need Help With Flutter Development?

Work with our skilled Flutter developers to accelerate your project and boost its performance.

Hire Flutter Developers

Support On Demand!

Related Q&A