# MixedFraction class Null safety

Dart representation of a mixed fraction which is composed by the whole part and a proper fraction. A proper fraction is a fraction in which the relation `numerator <= denominator` is true.

There's the possibility to create an instance of MixedFraction either by using one of the constructors or by using the extension methods on num and String.

``````final f = MixedFraction.fromDouble(1.5);
final f = MixedFraction.fromString("1 1/2");
``````

is equivalent to

``````final f = 1.5.toMixedFraction();
final f = "1 1/2".toMixedFraction();
``````

If the string doesn't represent a valid fraction, a MixedFractionException is thrown.

Implemented types

## Constructors

MixedFraction({required int whole, required int numerator, required int denominator})
Creates an instance of a mixed fraction. If the numerator isn't greater than the denominator, the values are automatically transformed so that a valid mixed fraction is created. For example: [...]
factory
MixedFraction.fromFraction(Fraction fraction)
Creates an instance of a mixed fraction.
factory
MixedFraction.fromString(String value)
Creates an instance of a mixed fraction. The input string must be in the form 'a b/c' with exactly one space between the whole part and the fraction. The fraction can also be a glyph. [...]
factory

## Properties

denominator int
Denominator of the fraction.
late, final
fractionalPart
Returns the fractional part of the mixed fraction as Fraction object.
hashCode int
The hash code for this object. [...]
isNegative bool
True or false whether the mixed fraction is positive or negative.
numerator int
Numerator of the fraction.
late, final
runtimeType Type
A representation of the runtime type of the object.
whole int
Whole part of the mixed fraction.
late, final

## Methods

compareTo(MixedFraction other) int
Compares this object to another object. [...]
override
copyWith({int? whole, int? numerator, int? denominator})
Creates a deep copy of this object with the given fields replaced with the new values.
negate()
Changes the sign of this mixed fraction and returns the results in a new MixedFraction instance.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
reduce()
Reduces this mixed fraction to the lowest terms and returns the results in a new MixedFraction instance.
toDouble()
Floating point representation of the mixed fraction.
toEgyptianFraction() List<Fraction>
Represents the current mixed fraction as an egyptian fraction. [...]
toFraction()
Converts this mixed fraction into a fraction.
toString()
A string representation of this object. [...]
override
toStringAsGlyph()
If possible, this method converts this MixedFraction instance into an unicode glyph string. For example: [...]

## Operators

operator *(MixedFraction other)
Multiplication between two mixed fractions.
operator +(MixedFraction other)
Sum between two mixed fractions.
operator -(MixedFraction other)
Difference between two mixed fractions.
operator /(MixedFraction other)
Division between two mixed fractions.
operator <(MixedFraction other) bool
Checks whether this mixed fraction is smaller than the other.
operator <=(MixedFraction other) bool
Checks whether this mixed fraction is smaller or equal than the other.
operator ==(Object other) bool
Two mixed fractions are equal if the whole part and the "cross product" of the fractional part is equal. [...]
override
operator >(MixedFraction other) bool
Checks whether this mixed fraction is greater than the other.
operator >=(MixedFraction other) bool
Checks whether this mixed fraction is greater or equal than the other.
operator [](int index) int
Access the whole part, the numerator or the denominator of the fraction via index. In particular: [...]