Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/web3/types/bignumber.d.ts>BigNumber#toFraction

Deno / TypeScript to Ethereum Connector
Latest
method BigNumber.prototype.toFraction
import { BigNumber } from "https://deno.land/x/web3@v0.11.1/types/bignumber.d.ts";

Returns an array of two BigNumbers representing the value of this BigNumber as a simple fraction with an integer numerator and an integer denominator. The denominator will be a positive non-zero value less than or equal to max_denominator. If a maximum denominator, max_denominator, is not specified, or is null or undefined, the denominator will be the lowest value necessary to represent the number exactly.

Throws if max_denominator is invalid.

x = new BigNumber(1.75)
x.toFraction()                  // '7, 4'

pi = new BigNumber('3.14159265358')
pi.toFraction()                 // '157079632679,50000000000'
pi.toFraction(100000)           // '312689, 99532'
pi.toFraction(10000)            // '355, 113'
pi.toFraction(100)              // '311, 99'
pi.toFraction(10)               // '22, 7'
pi.toFraction(1)                // '3, 1'

Parameters

optional
max_denominator: BigNumber.Value