JavaScript

NumbertoFraction Method

Syntax

Number.toFraction([denominator])

Arguments

denominatornumber

The denominator to use in the fraction. If no value (or zero) is passed in then the lowest common denominator is used.

Returns

valuestring

A string with the fractional representation of the number.

Description

Extension to the native number variable to convert a number into a fractional.

Example

var num = 10.45;
var numStr = num.toFraction(); // numStr = '10 9/20'