Dart int truncate()
Syntax & Examples


int.truncate() method

The `truncate` method in Dart returns this truncated to an integer.


Syntax of int.truncate()

The syntax of int.truncate() method is:

 int truncate() 

This truncate() method of int returns this.

Return Type

int.truncate() returns value of type int.



✐ Example

1 Truncate of an integer

In this example,

  1. We create an integer variable integerNum with the value 7, which is already an integer.
  2. We use the truncate() method to get its integer value, which remains the same as it's already an integer.
  3. We then print the result to standard output.

Dart Program

void main() {
  int integerNum = 7;
  int truncInteger = integerNum.truncate();
  print('Truncate of $integerNum: $truncInteger');
}

Output

Truncate of 7: 7

Summary

In this Dart tutorial, we learned about truncate() method of int: the syntax and few working examples with output and detailed explanation for each example.