RoundingMode enum
Defines standard rounding modes for numerical rounding
Values
- floor → const RoundingMode
-
Rounds towards negative infinity
Example:
Rational.parse("-2.7").rounded(RoundingMode.floor); // -3 Rational.parse("2.7").rounded(RoundingMode.floor); // 2 - ceil → const RoundingMode
-
Rounds towards positive infinity
Example:
Rational.parse("-2.3").rounded(RoundingMode.ceil); // -2 Rational.parse("2.3").rounded(RoundingMode.ceil); // 3 - truncate → const RoundingMode
-
Rounds towards zero (truncates fractional part)
Example:
Rational.parse("-2.7").rounded(RoundingMode.truncate); // -2 Rational.parse("2.7").rounded(RoundingMode.truncate); // 2 - up → const RoundingMode
-
Rounds away from zero, increasing the magnitude of the number
- Positive values round up (toward +∞)
- Negative values round down (toward -∞)
Example:
Rational.parse("-2.3").rounded(RoundingMode.up); // -3 Rational.parse("2.3").rounded(RoundingMode.up); // 3 Rational.parse("-2.9").rounded(RoundingMode.up); // -3 Rational.parse("2.9").rounded(RoundingMode.up); // 3 - halfUp → const RoundingMode
-
Rounds to the nearest integer using half-up rounding
- If the fractional part is
>= 0.5, rounds up - Otherwise, rounds down
Example:
Rational.parse("2.5").rounded(RoundingMode.halfUp); // 3 Rational.parse("2.4").rounded(RoundingMode.halfUp); // 2 Rational.parse("-2.5").rounded(RoundingMode.halfUp); // -3 - If the fractional part is
- halfDown → const RoundingMode
-
Rounds to the nearest integer using half-down rounding
- If the fractional part is
> 0.5, rounds up - Otherwise, rounds down
Example:
Rational.parse("2.5").rounded(RoundingMode.halfDown); // 2 Rational.parse("2.6").rounded(RoundingMode.halfDown); // 3 Rational.parse("-2.5").rounded(RoundingMode.halfDown); // -2 - If the fractional part is
- halfEven → const RoundingMode
-
Rounds to the nearest even integer in case of a tie
Example:
Rational.parse("2.5").rounded(RoundingMode.halfEven); // 2 Rational.parse("3.5").rounded(RoundingMode.halfEven); // 4 Rational.parse("-2.5").rounded(RoundingMode.halfEven); // -2 Rational.parse("-3.5").rounded(RoundingMode.halfEven); // -4
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- index → int
-
A numeric identifier for the enumerated value.
no setterinherited
- name → String
-
Available on Enum, provided by the EnumName extension
The name of the enum value.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
-
values
→ const List<
RoundingMode> - A constant List of the values in this enum, in order of their declaration.