Dart API Referencedart:corenum

num abstract class

All numbers in dart are instances of num.

abstract class num implements Comparable {
  /** Addition operator. */
  num operator +(num other);

  /** Subtraction operator. */
  num operator -(num other);

  /** Multiplication operator. */
  num operator *(num other);

  /** Euclidean modulo operator. */
  num operator %(num other);

  /** Division operator. */
  double operator /(num other);

  /**
   * Truncating division operator.
   *
   * The result of the truncating division [:a ~/ b:] is equivalent to
   * [:(a / b).truncate():].
   */
  num operator ~/(num other);

  /** Negate operator. */
  num operator -();

  /** Return the remainder from dividing this [num] by [other]. */
  num remainder(num other);

  /** Relational less than operator. */
  bool operator <(num other);

  /** Relational less than or equal operator. */
  bool operator <=(num other);

  /** Relational greater than operator. */
  bool operator >(num other);

  /** Relational greater than or equal operator. */
  bool operator >=(num other);

  bool get isNaN;

  bool get isNegative;

  bool get isInfinite;

  /** Returns the absolute value of this [num]. */
  num abs();

  /** Returns the greatest integer value no greater than this [num]. */
  num floor();

  /** Returns the least integer value that is no smaller than this [num]. */
  num ceil();

  /**
   * Returns the integer value closest to this [num].
   *
   * Rounds away from zero when there is no closest integer:
   *  [:(3.5).round() == 4:] and [:(-3.5).round() == -4:].
   */
  num round();

  /**
   * Returns the integer value obtained by discarding any fractional
   * digits from this [num].
   */
  num truncate();

  /** Truncates this [num] to an integer and returns the result as an [int]. */
  int toInt();

  /**
   * Return this [num] as a [double].
   *
   * If the number is not representable as a [double], an
   * approximation is returned. For numerically large integers, the
   * approximation may be infinite.
   */
  double toDouble();

  /**
   * Converts a [num] to a string representation with [fractionDigits]
   * digits after the decimal point.
   */
  String toStringAsFixed(int fractionDigits);

  /**
   * Converts a [num] to a string in decimal exponential notation with
   * [fractionDigits] digits after the decimal point.
   */
  String toStringAsExponential(int fractionDigits);

  /**
   * Converts a [num] to a string representation with [precision]
   * significant digits.
   */
  String toStringAsPrecision(int precision);

  /**
   * Converts a [num] to a string representation in the given [radix].
   *
   * The [num] in converted to an [int] using [toInt]. That [int] is
   * then converted to a string representation with the given
   * [radix]. In the string representation, lower-case letters are
   * used for digits above '9'.
   *
   * The [radix] argument must be an integer between 2 and 36.
   */
  String toRadixString(int radix);
}

Subclasses

double, int

Implements

Comparable

Properties

final bool isInfinite #

bool get isInfinite;

final bool isNaN #

bool get isNaN;

final bool isNegative #

bool get isNegative;

Operators

num operator +(num other) #

Addition operator.

num operator +(num other);

num operator -() #

Negate operator.

num operator -();

num operator -(num other) #

Subtraction operator.

num operator -(num other);

num operator *(num other) #

Multiplication operator.

num operator *(num other);

double operator /(num other) #

Division operator.

double operator /(num other);

num operator ~/(num other) #

Truncating division operator.

The result of the truncating division a ~/ b is equivalent to (a / b).truncate().

num operator ~/(num other);

num operator %(num other) #

Euclidean modulo operator.

num operator %(num other);

bool operator <(num other) #

Relational less than operator.

bool operator <(num other);

bool operator <=(num other) #

Relational less than or equal operator.

bool operator <=(num other);

bool operator >(num other) #

Relational greater than operator.

bool operator >(num other);

bool operator >=(num other) #

Relational greater than or equal operator.

bool operator >=(num other);

Methods

num abs() #

Returns the absolute value of this num.

num abs();

num ceil() #

Returns the least integer value that is no smaller than this num.

num ceil();

abstract int compareTo(Comparable other) #

inherited from Comparable

Compares this object to another Comparable

Returns a value like a Comparator when comparing this to other.

May throw an ArgumentError if other is of a type that is not comparable to this.

num floor() #

Returns the greatest integer value no greater than this num.

num floor();

num remainder(num other) #

Return the remainder from dividing this num by other.

num remainder(num other);

num round() #

Returns the integer value closest to this num.

Rounds away from zero when there is no closest integer: (3.5).round() == 4 and (-3.5).round() == -4.

num round();

double toDouble() #

Return this num as a double.

If the number is not representable as a double, an approximation is returned. For numerically large integers, the approximation may be infinite.

double toDouble();

int toInt() #

Truncates this num to an integer and returns the result as an int.

int toInt();

String toRadixString(int radix) #

Converts a num to a string representation in the given radix.

The num in converted to an int using toInt. That int is then converted to a string representation with the given radix. In the string representation, lower-case letters are used for digits above '9'.

The radix argument must be an integer between 2 and 36.

String toRadixString(int radix);

String toStringAsExponential(int fractionDigits) #

Converts a num to a string in decimal exponential notation with fractionDigits digits after the decimal point.

String toStringAsExponential(int fractionDigits);

String toStringAsFixed(int fractionDigits) #

Converts a num to a string representation with fractionDigits digits after the decimal point.

String toStringAsFixed(int fractionDigits);

String toStringAsPrecision(int precision) #

Converts a num to a string representation with precision significant digits.

String toStringAsPrecision(int precision);

num truncate() #

Returns the integer value obtained by discarding any fractional digits from this num.

num truncate();