# Rational

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Fields](https://developer.android.com/reference/android/util/Rational#lfields)\|[Ctors](https://developer.android.com/reference/android/util/Rational#pubctors)\|[Methods](https://developer.android.com/reference/android/util/Rational#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/util/Rational#inhmethods)  

# Rational

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/util/Rational "View this page in Kotlin")\|Java

`
public

final

class
Rational
`  
`


``

extends `[Number](https://developer.android.com/reference/java/lang/Number)`


``


implements

`[Comparable](https://developer.android.com/reference/java/lang/Comparable)`<`[Rational](https://developer.android.com/reference/android/util/Rational)`>


`

|---|---|-----------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) |||
| ↳ | [java.lang.Number](https://developer.android.com/reference/java/lang/Number) ||
|   | ↳ | android.util.Rational |

<br />

*** ** * ** ***

<br />

An immutable data type representation a rational number.

Contains a pair of`int`s representing the numerator and denominator of a Rational number.

<br />

## Summary

|                                                                                                                              ### Fields                                                                                                                               ||
|--------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` public static final `[Rational](https://developer.android.com/reference/android/util/Rational) | [NEGATIVE_INFINITY](https://developer.android.com/reference/android/util/Rational#NEGATIVE_INFINITY) Constant for the negative infinity value of the`Rational`type. |
| ` public static final `[Rational](https://developer.android.com/reference/android/util/Rational) | [NaN](https://developer.android.com/reference/android/util/Rational#NaN) Constant for the*Not-a-Number (NaN)* value of the`Rational`type.                           |
| ` public static final `[Rational](https://developer.android.com/reference/android/util/Rational) | [POSITIVE_INFINITY](https://developer.android.com/reference/android/util/Rational#POSITIVE_INFINITY) Constant for the positive infinity value of the`Rational`type. |
| ` public static final `[Rational](https://developer.android.com/reference/android/util/Rational) | [ZERO](https://developer.android.com/reference/android/util/Rational#ZERO) Constant for the zero value of the`Rational`type.                                        |

|                                                                                         ### Public constructors                                                                                          ||
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[Rational](https://developer.android.com/reference/android/util/Rational#Rational(int,%20int))`(int numerator, int denominator) ` <br /> Create a`Rational`with a given numerator and denominator. |

|                                                                                                                                                                                                                 ### Public methods                                                                                                                                                                                                                 ||
|-------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` int`                                                                              | ` `[compareTo](https://developer.android.com/reference/android/util/Rational#compareTo(android.util.Rational))`(`[Rational](https://developer.android.com/reference/android/util/Rational)` another) ` Compare this rational to the specified rational to determine their natural order.                                                                      |
| ` double`                                                                           | ` `[doubleValue](https://developer.android.com/reference/android/util/Rational#doubleValue())`() ` Returns the value of the specified number as a`double`.                                                                                                                                                                                                    |
| ` boolean`                                                                          | ` `[equals](https://developer.android.com/reference/android/util/Rational#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` <br /> Compare this Rational to another object and see if they are equal.                                                                                                    |
| ` float`                                                                            | ` `[floatValue](https://developer.android.com/reference/android/util/Rational#floatValue())`() ` Returns the value of the specified number as a`float`.                                                                                                                                                                                                       |
| ` int`                                                                              | ` `[getDenominator](https://developer.android.com/reference/android/util/Rational#getDenominator())`() ` Gets the denominator of the rational The denominator may return`0`, in which case the rational may represent positive infinity (if the numerator was positive), negative infinity (if the numerator was negative), or`NaN`(if the numerator was`0`). |
| ` int`                                                                              | ` `[getNumerator](https://developer.android.com/reference/android/util/Rational#getNumerator())`() ` Gets the numerator of the rational.                                                                                                                                                                                                                      |
| ` int`                                                                              | ` `[hashCode](https://developer.android.com/reference/android/util/Rational#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                                                                                        |
| ` int`                                                                              | ` `[intValue](https://developer.android.com/reference/android/util/Rational#intValue())`() ` Returns the value of the specified number as a`int`.                                                                                                                                                                                                             |
| ` boolean`                                                                          | ` `[isFinite](https://developer.android.com/reference/android/util/Rational#isFinite())`() ` Indicates whether this rational represents a finite value.                                                                                                                                                                                                       |
| ` boolean`                                                                          | ` `[isInfinite](https://developer.android.com/reference/android/util/Rational#isInfinite())`() ` Indicates whether this rational represents an infinite value.                                                                                                                                                                                                |
| ` boolean`                                                                          | ` `[isNaN](https://developer.android.com/reference/android/util/Rational#isNaN())`() ` Indicates whether this rational is a*Not-a-Number (NaN)*value.                                                                                                                                                                                                         |
| ` boolean`                                                                          | ` `[isZero](https://developer.android.com/reference/android/util/Rational#isZero())`() ` Indicates whether this rational represents a zero value.                                                                                                                                                                                                             |
| ` long`                                                                             | ` `[longValue](https://developer.android.com/reference/android/util/Rational#longValue())`() ` Returns the value of the specified number as a`long`.                                                                                                                                                                                                          |
| ` static `[Rational](https://developer.android.com/reference/android/util/Rational) | ` `[parseRational](https://developer.android.com/reference/android/util/Rational#parseRational(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` string) ` Parses the specified string as a rational value.                                                                                                            |
| ` short`                                                                            | ` `[shortValue](https://developer.android.com/reference/android/util/Rational#shortValue())`() ` Returns the value of the specified number as a`short`.                                                                                                                                                                                                       |
| ` `[String](https://developer.android.com/reference/java/lang/String)               | ` `[toString](https://developer.android.com/reference/android/util/Rational#toString())`() ` Return a string representation of this rational, e.g.`"1/2"`.                                                                                                                                                                                                    |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Number](https://developer.android.com/reference/java/lang/Number)` ` |--------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------| | ` byte`            | ` `[byteValue](https://developer.android.com/reference/java/lang/Number#byteValue())`() ` Returns the value of the specified number as a`byte`.       | | ` abstract double` | ` `[doubleValue](https://developer.android.com/reference/java/lang/Number#doubleValue())`() ` Returns the value of the specified number as a`double`. | | ` abstract float`  | ` `[floatValue](https://developer.android.com/reference/java/lang/Number#floatValue())`() ` Returns the value of the specified number as a`float`.    | | ` abstract int`    | ` `[intValue](https://developer.android.com/reference/java/lang/Number#intValue())`() ` Returns the value of the specified number as an`int`.         | | ` abstract long`   | ` `[longValue](https://developer.android.com/reference/java/lang/Number#longValue())`() ` Returns the value of the specified number as a`long`.       | | ` short`           | ` `[shortValue](https://developer.android.com/reference/java/lang/Number#shortValue())`() ` Returns the value of the specified number as a`short`.    | ||
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||
| From interface` `[java.lang.Comparable](https://developer.android.com/reference/java/lang/Comparable)` ` |-----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract int` | ` `[compareTo](https://developer.android.com/reference/java/lang/Comparable#compareTo(T))`(`[Rational](https://developer.android.com/reference/android/util/Rational)` o) ` Compares this object with the specified object for order. | ||

## Fields

### NEGATIVE_INFINITY

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final Rational NEGATIVE_INFINITY
```

Constant for the negative infinity value of the`Rational`type.

Equivalent to constructing a new rational with a negative numerator and a denominator equal to`0`.

<br />

<br />

### NaN

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final Rational NaN
```

Constant for the*Not-a-Number (NaN)* value of the`Rational`type.

A`NaN`value is considered to be equal to itself (that is`NaN.equals(NaN)`will return`true`; it is always greater than any non-`NaN`value (that is`NaN.compareTo(notNaN)`will return a number greater than`0`).

Equivalent to constructing a new rational with both the numerator and denominator equal to`0`.

<br />

<br />

### POSITIVE_INFINITY

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final Rational POSITIVE_INFINITY
```

Constant for the positive infinity value of the`Rational`type.

Equivalent to constructing a new rational with a positive numerator and a denominator equal to`0`.

<br />

<br />

### ZERO

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final Rational ZERO
```

Constant for the zero value of the`Rational`type.

Equivalent to constructing a new rational with a numerator equal to`0`and any non-zero denominator.

<br />

<br />

## Public constructors

### Rational

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Rational (int numerator, 
                int denominator)
```

<br />

Create a`Rational`with a given numerator and denominator.

The signs of the numerator and the denominator may be flipped such that the denominator is always positive. Both the numerator and denominator will be converted to their reduced forms (see[equals(Object)](https://developer.android.com/reference/android/util/Rational#equals(java.lang.Object))for more details).

For example,

- a rational of`2/4`will be reduced to`1/2`.
- a rational of`1/-1`will be flipped to`-1/1`
- a rational of`5/0`will be reduced to`1/0`
- a rational of`0/5`will be reduced to`0/1`

<br />

<br />

<br />

|                          Parameters                          ||
|---------------|-----------------------------------------------|
| `numerator`   | `int`: the numerator of the rational <br />   |
| `denominator` | `int`: the denominator of the rational <br /> |

**See also:**

- [equals(Object)](https://developer.android.com/reference/android/util/Rational#equals(java.lang.Object))

## Public methods

### compareTo

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int compareTo (Rational another)
```

Compare this rational to the specified rational to determine their natural order.

[NaN](https://developer.android.com/reference/android/util/Rational#NaN)is considered to be equal to itself and greater than all other`Rational`values. Otherwise, if the objects are not[equal](https://developer.android.com/reference/android/util/Rational#equals(java.lang.Object)), then the following rules apply:

- Positive infinity is greater than any other finite number (or negative infinity)
- Negative infinity is less than any other finite number (or positive infinity)
- The finite number represented by this rational is checked numerically against the other finite number by converting both rationals to a common denominator multiple and comparing their numerators.

<br />

<br />

|                        Parameters                         ||
|-----------|------------------------------------------------|
| `another` | `Rational`: the rational to be compared <br /> |

|                                                                   Returns                                                                    ||
|-------|---------------------------------------------------------------------------------------------------------------------------------------|
| `int` | a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified rational. <br /> |

|                                                        Throws                                                        ||
|------------------------------------------------------------------------------------------------|----------------------|
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException) | if`another`was`null` |

### doubleValue

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public double doubleValue ()
```

Returns the value of the specified number as a`double`.

The`double`is calculated by converting both the numerator and denominator to a`double`; then returning the result of dividing the numerator by the denominator.

<br />

<br />

|                                      Returns                                      ||
|----------|-------------------------------------------------------------------------|
| `double` | the divided value of the numerator and denominator as a`double`. <br /> |

### equals

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean equals (Object obj)
```

<br />

Compare this Rational to another object and see if they are equal.

A Rational object can only be equal to another Rational object (comparing against any other type will return`false`).

A Rational object is considered equal to another Rational object if and only if one of the following holds:

- Both are`NaN`
- Both are infinities of the same sign
- Both have the same numerator and denominator in their reduced form

A reduced form of a Rational is calculated by dividing both the numerator and the denominator by their greatest common divisor.  

    (new Rational(1, 2)).equals(new Rational(1, 2)) == true   // trivially true
     (new Rational(2, 3)).equals(new Rational(1, 2)) == false  // trivially false
     (new Rational(1, 2)).equals(new Rational(2, 4)) == true   // true after reduction
     (new Rational(0, 0)).equals(new Rational(0, 0)) == true   // NaN.equals(NaN)
     (new Rational(1, 0)).equals(new Rational(5, 0)) == true   // both are +infinity
     (new Rational(1, 0)).equals(new Rational(-1, 0)) == false // +infinity != -infinity
     
<br />

<br />

|                                   Parameters                                   ||
|-------|-------------------------------------------------------------------------|
| `obj` | `Object`: a reference to another object This value may be`null`. <br /> |

|                                            Returns                                             ||
|-----------|-------------------------------------------------------------------------------------|
| `boolean` | A boolean that determines whether or not the two Rational objects are equal. <br /> |

### floatValue

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public float floatValue ()
```

Returns the value of the specified number as a`float`.

The`float`is calculated by converting both the numerator and denominator to a`float`; then returning the result of dividing the numerator by the denominator.

<br />

<br />

|                                     Returns                                     ||
|---------|------------------------------------------------------------------------|
| `float` | the divided value of the numerator and denominator as a`float`. <br /> |

### getDenominator

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int getDenominator ()
```

Gets the denominator of the rational

The denominator may return`0`, in which case the rational may represent positive infinity (if the numerator was positive), negative infinity (if the numerator was negative), or`NaN`(if the numerator was`0`).

The denominator will always return`1`if the numerator is`0`.

<br />

|    Returns    ||
|-------|--------|
| `int` | <br /> |

### getNumerator

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int getNumerator ()
```

Gets the numerator of the rational.

The numerator will always return`1`if this rational represents infinity (that is, the denominator is`0`).

<br />

<br />

|    Returns    ||
|-------|--------|
| `int` | <br /> |

### hashCode

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int hashCode ()
```

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by[HashMap](https://developer.android.com/reference/java/util/HashMap).

The general contract of`hashCode`is:

- Whenever it is invoked on the same object more than once during an execution of a Java application, the`hashCode`method must consistently return the same integer, provided no information used in`equals`comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
- If two objects are equal according to the[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))method, then calling the`hashCode`method on each of the two objects must produce the same integer result.
- It is*not* required that if two objects are unequal according to the[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))method, then calling the`hashCode`method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.

<br />

<br />

|                     Returns                      ||
|-------|-------------------------------------------|
| `int` | a hash code value for this object. <br /> |

### intValue

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int intValue ()
```

Returns the value of the specified number as a`int`.

[Finite](https://developer.android.com/reference/android/util/Rational#isInfinite())rationals are converted to an`int`value by dividing the numerator by the denominator; conversion for non-finite values happens identically to casting a floating point value to an`int`, in particular:

<br />

- Positive infinity saturates to the largest maximum integer[Integer.MAX_VALUE](https://developer.android.com/reference/java/lang/Integer#MAX_VALUE)
- Negative infinity saturates to the smallest maximum integer[Integer.MIN_VALUE](https://developer.android.com/reference/java/lang/Integer#MIN_VALUE)
- *Not-A-Number (NaN)* returns`0`.

<br />

<br />

<br />

|                                   Returns                                   ||
|-------|----------------------------------------------------------------------|
| `int` | the divided value of the numerator and denominator as a`int`. <br /> |

### isFinite

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean isFinite ()
```

Indicates whether this rational represents a finite value.

A finite value occurs when the denominator is not`0`; in other words the rational is neither infinity or`NaN`.

<br />

<br />

|                                                                Returns                                                                ||
|-----------|----------------------------------------------------------------------------------------------------------------------------|
| `boolean` | `true`if this rational is a (positive or negative) infinite value;`false`if this is a finite number value (or`NaN`) <br /> |

### isInfinite

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean isInfinite ()
```

Indicates whether this rational represents an infinite value.

An infinite value occurs when the denominator is`0`(but the numerator is not).

<br />

<br />

|                                                                Returns                                                                ||
|-----------|----------------------------------------------------------------------------------------------------------------------------|
| `boolean` | `true`if this rational is a (positive or negative) infinite value;`false`if this is a finite number value (or`NaN`) <br /> |

### isNaN

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean isNaN ()
```

Indicates whether this rational is a*Not-a-Number (NaN)*value.

A`NaN`value occurs when both the numerator and the denominator are`0`.

<br />

<br />

|                                                             Returns                                                             ||
|-----------|----------------------------------------------------------------------------------------------------------------------|
| `boolean` | `true`if this rational is a*Not-a-Number (NaN)* value;`false`if this is a (potentially infinite) number value <br /> |

### isZero

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean isZero ()
```

Indicates whether this rational represents a zero value.

A zero value is a[finite](https://developer.android.com/reference/android/util/Rational#isFinite())rational with a numerator of`0`.

<br />

<br />

|                                    Returns                                     ||
|-----------|---------------------------------------------------------------------|
| `boolean` | `true`if this rational is finite zero value;`false`otherwise <br /> |

### longValue

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public long longValue ()
```

Returns the value of the specified number as a`long`.

[Finite](https://developer.android.com/reference/android/util/Rational#isInfinite())rationals are converted to an`long`value by dividing the numerator by the denominator; conversion for non-finite values happens identically to casting a floating point value to a`long`, in particular:

<br />

- Positive infinity saturates to the largest maximum long[Long.MAX_VALUE](https://developer.android.com/reference/java/lang/Long#MAX_VALUE)
- Negative infinity saturates to the smallest maximum long[Long.MIN_VALUE](https://developer.android.com/reference/java/lang/Long#MIN_VALUE)
- *Not-A-Number (NaN)* returns`0`.

<br />

<br />

<br />

|                                    Returns                                    ||
|--------|-----------------------------------------------------------------------|
| `long` | the divided value of the numerator and denominator as a`long`. <br /> |

### parseRational

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static Rational parseRational (String string)
```

Parses the specified string as a rational value.

The ASCII characters`\``u003a`(':') and`\``u002f`('/') are recognized as separators between the numerator and denumerator.

For any`Rational r`:`Rational.parseRational(r.toString()).equals(r)`. However, the method also handles rational numbers expressed in the following forms:

"*num* `/`*den* " or "*num* `:`*den* "`=> new Rational(num, den);`, where*num* and*den*are string integers potentially containing a sign, such as "-10", "+7" or "5".  

    Rational.parseRational("3:+6").equals(new Rational(1, 2)) == true
     Rational.parseRational("-3/-6").equals(new Rational(1, 2)) == true
     Rational.parseRational("4.56") => throws NumberFormatException
     
<br />

<br />

|                                Parameters                                 ||
|----------|-----------------------------------------------------------------|
| `string` | `String`: the string representation of a rational value. <br /> |

|                                                           Returns                                                            ||
|---------------------------------------------------------------------------|---------------------------------------------------|
| [Rational](https://developer.android.com/reference/android/util/Rational) | the rational value represented by`string`. <br /> |

|                                                                      Throws                                                                       ||
|--------------------------------------------------------------------------------------------------|-------------------------------------------------|
| [NumberFormatException](https://developer.android.com/reference/java/lang/NumberFormatException) | if`string`cannot be parsed as a rational value. |
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)   | if`string`was`null`                             |

### shortValue

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public short shortValue ()
```

Returns the value of the specified number as a`short`.

[Finite](https://developer.android.com/reference/android/util/Rational#isInfinite())rationals are converted to a`short`value identically to[intValue()](https://developer.android.com/reference/android/util/Rational#intValue()); the`int`result is then truncated to a`short`before returning the value.

<br />

<br />

|                                     Returns                                     ||
|---------|------------------------------------------------------------------------|
| `short` | the divided value of the numerator and denominator as a`short`. <br /> |

### toString

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public String toString ()
```

Return a string representation of this rational, e.g.`"1/2"`.

The following rules of conversion apply:

- `NaN`values will return`"NaN"`
- Positive infinity values will return`"Infinity"`
- Negative infinity values will return`"-Infinity"`
- All other values will return`"numerator/denominator"`where`numerator`and`denominator`are substituted with the appropriate numerator and denominator values.

<br />

<br />

<br />

|                                                      Returns                                                      ||
|--------------------------------------------------------------------|-----------------------------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | a string representation of the object. <br /> |