trunc function

double trunc(
  1. double x
)

Returns the integer part of a number by removing any fractional digits.

x is the input value.

If x is NaN, returns NaN. If x is positive, returns the floor value of x. Otherwise, returns the ceil value of x.

Example: ``dart print(trunc(4.7)); // Output: 4 print(trunc(-4.7)); // Output: -4

Implementation

double trunc(double x) {
  if (x.isNaN) return double.nan;
  if (x > 0) return x.floorToDouble();
  return x.ceilToDouble();
}