# Class BigFraction

java.lang.Object
java.lang.Number
com.aoapps.lang.math.BigFraction
All Implemented Interfaces:
`Serializable`, `Comparable<BigFraction>`

public class BigFraction extends Number implements Serializable, Comparable<BigFraction>
Stores arbitrary size fractions by their numerator and denominator.
Author:
AO Industries, Inc.
• ## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static enum `
`BigFraction.DistributionMethod`

• ## Field Summary

Fields
Modifier and Type
Field
Description
`static final BigFraction`
`ONE`

`static final BigFraction`
`ZERO`

• ## Constructor Summary

Constructors
Constructor
Description
```BigFraction(long numerator, long denominator, boolean displayPercentage)```

`BigFraction(String value)`

```BigFraction(BigInteger numerator, BigInteger denominator, boolean displayPercentage)```

• ## Method Summary

Modifier and Type
Method
Description
`BigFraction`
`abs()`
Gets the absolute value, but is not reduced.
`BigFraction`
`add(BigFraction val)`
Adds two fractions, returning the value in lowest terms.
`int`
`compareTo(BigFraction o)`

`static BigDecimal[]`
```distributeValue(BigDecimal total, BigFraction.DistributionMethod distributionMethod, BigFraction... fractions)```
Evenly distributes the total value of BigDecimal by fractional amounts.
`BigFraction`
`divide(BigFraction val)`
Divides two fractions, returning the value in lowest terms.
`double`
`doubleValue()`

`boolean`
`equals(Object obj)`
Two fractions are equal when they have both the same numerator, denominator, and displayPercentage.
`float`
`floatValue()`

`BigDecimal`
`getBigDecimal(int scale)`
Gets this fraction as a BigDecimal using `RoundingMode.UNNECESSARY`.
`BigDecimal`
```getBigDecimal(int scale, RoundingMode roundingMode)```
Gets this fraction as a BigDecimal using the provided rounding mode.
`BigInteger`
`getBigInteger()`
Gets this fraction as a BigInteger using `RoundingMode.UNNECESSARY`.
`BigInteger`
`getBigInteger(RoundingMode roundingMode)`
Gets this fraction as a BigInteger using the provided rounding mode.
`BigInteger`
`getDenominator()`

`BigInteger`
`getNumerator()`

`int`
`hashCode()`

`int`
`intValue()`

`boolean`
`isDisplayPercentage()`

`long`
`longValue()`

`BigFraction`
`max(BigFraction val)`
Gets the higher of the two fractions.
`BigFraction`
`min(BigFraction val)`
Gets the lower of the two fractions.
`BigFraction`
`multiply(BigFraction val)`
Multiplies two fractions, returning the value in lowest terms.
`BigFraction`
`negate()`
Negates the value, but is not reduced.
`BigFraction`
`pow(int exponent)`
Raises this fraction to the provided exponent, returning the value in lowest terms.
`BigFraction`
`reduce()`
Reduces this fraction to its lowest terms.
`int`
`signum()`
Returns the signum function of this `BigFraction`.
`BigFraction`
`subtract(BigFraction val)`
Subtracts two fractions, returning the value in lowest terms.
`String`
`toString()`

`static BigFraction`
```valueOf(long numerator, long denominator, boolean displayPercentage)```

`static BigFraction`
```valueOf(BigDecimal value, boolean displayPercentage)```
Gets the big decimal as a fraction, reduced.
`static BigFraction`
```valueOf(BigInteger value, boolean displayPercentage)```

`static BigFraction`
```valueOf(BigInteger numerator, BigInteger denominator, boolean displayPercentage)```

### Methods inherited from class java.lang.Number

`byteValue, shortValue`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`
• ## Field Details

• ### ZERO

public static final BigFraction ZERO
• ### ONE

public static final BigFraction ONE
• ## Constructor Details

• ### BigFraction

public BigFraction(String value) throws NumberFormatException
Throws:
`NumberFormatException`
• ### BigFraction

public BigFraction(long numerator, long denominator, boolean displayPercentage) throws NumberFormatException
Throws:
`NumberFormatException`
• ### BigFraction

public BigFraction(BigInteger numerator, BigInteger denominator, boolean displayPercentage) throws NumberFormatException
Throws:
`NumberFormatException`
• ## Method Details

• ### valueOf

public static BigFraction valueOf(long numerator, long denominator, boolean displayPercentage) throws NumberFormatException
Throws:
`NumberFormatException`
• ### valueOf

public static BigFraction valueOf(BigInteger value, boolean displayPercentage) throws NumberFormatException
Throws:
`NumberFormatException`
• ### valueOf

public static BigFraction valueOf(BigDecimal value, boolean displayPercentage) throws NumberFormatException
Gets the big decimal as a fraction, reduced.
Throws:
`NumberFormatException`
• ### valueOf

public static BigFraction valueOf(BigInteger numerator, BigInteger denominator, boolean displayPercentage) throws NumberFormatException
Throws:
`NumberFormatException`
• ### distributeValue

public static  distributeValue(BigDecimal total, BigFraction.DistributionMethod distributionMethod, BigFraction... fractions)
Evenly distributes the total value of BigDecimal by fractional amounts.
• The sum of the results will equal `total`.
• The results will use the same scale as `total`.
• The results will be rounded where necessary to match the scale of `total`.
• Each result will be zero or have a sign matching `total`.
Parameters:
`total` - The total value to be distributed within the results
`fractions` - The fractional amount of each result, the sum must be equal to one. The array elements are unmodified.
Returns:
the results corresponding to each fractional amount.
• ### toString

public String toString()
Overrides:
`toString` in class `Object`
• ### getNumerator

public BigInteger getNumerator()
• ### getDenominator

public BigInteger getDenominator()
• ### isDisplayPercentage

public boolean isDisplayPercentage()
• ### intValue

public int intValue()
Specified by:
`intValue` in class `Number`
• ### longValue

public long longValue()
Specified by:
`longValue` in class `Number`
• ### floatValue

public float floatValue()
Specified by:
`floatValue` in class `Number`
• ### doubleValue

public double doubleValue()
Specified by:
`doubleValue` in class `Number`
• ### getBigInteger

public BigInteger getBigInteger() throws ArithmeticException
Gets this fraction as a BigInteger using `RoundingMode.UNNECESSARY`.
Throws:
`ArithmeticException`
• ### getBigInteger

public BigInteger getBigInteger(RoundingMode roundingMode) throws ArithmeticException
Gets this fraction as a BigInteger using the provided rounding mode.
Throws:
`ArithmeticException`
• ### getBigDecimal

public BigDecimal getBigDecimal(int scale) throws ArithmeticException
Gets this fraction as a BigDecimal using `RoundingMode.UNNECESSARY`.
Throws:
`ArithmeticException`
• ### getBigDecimal

public BigDecimal getBigDecimal(int scale, RoundingMode roundingMode) throws ArithmeticException
Gets this fraction as a BigDecimal using the provided rounding mode.
Throws:
`ArithmeticException`
• ### hashCode

public int hashCode()
Overrides:
`hashCode` in class `Object`
• ### equals

public boolean equals(Object obj)
Two fractions are equal when they have both the same numerator, denominator, and displayPercentage. For numerical equality independent of denominator, use `compareTo`.
Overrides:
`equals` in class `Object`
• ### compareTo

public int compareTo(BigFraction o)
Specified by:
`compareTo` in interface `Comparable<BigFraction>`
• ### reduce

public BigFraction reduce()
Reduces this fraction to its lowest terms.

Adds two fractions, returning the value in lowest terms.

If either is a percentage, the result will be a percentage.

• ### subtract

public BigFraction subtract(BigFraction val)
Subtracts two fractions, returning the value in lowest terms.

If either is a percentage, the result will be a percentage.

• ### multiply

public BigFraction multiply(BigFraction val)
Multiplies two fractions, returning the value in lowest terms.

If both are percentages, the result will be a percentage.

• ### divide

public BigFraction divide(BigFraction val)
Divides two fractions, returning the value in lowest terms.
• If percent divide by percent: percent
• If percent divide by non-percent: percent
• If non-percent divide by percent: non-percent
• If non-percent divide by non-percent: non-percent
• ### negate

public BigFraction negate()
Negates the value, but is not reduced.
• ### abs

public BigFraction abs()
Gets the absolute value, but is not reduced.
• ### max

public BigFraction max(BigFraction val)
Gets the higher of the two fractions. When they are equal the one with the lower denominator is returned. When their denominators are also equal, returns `this`.
• ### min

public BigFraction min(BigFraction val)
Gets the lower of the two fractions. When they are equal the one with the lower denominator is returned. When their denominators are also equal, returns `this`.
• ### pow

public BigFraction pow(int exponent)
Raises this fraction to the provided exponent, returning the value in lowest terms.
• ### signum

public int signum()
Returns the signum function of this `BigFraction`.
Returns:
-1, 0, or 1 as the value of this `BigFraction` is negative, zero, or positive.