Hide menu
Loading...
Searching...
No Matches
Ratio

Holds a ratio in the form of (n:m).

Can be used to define the scale factor in certain situations. The numerator and denominator are stored as assigned and are not reduced.

Constructors

Constructor

new Ratio(numerator?, denominator?): Ratio

Creates a ratio.

If no arguments are provided, the ratio is initialized as (1:1). Passing 0 as numerator is allowed but usually does not make practical sense. The constructor throws a RangeError if denominator is 0.

Parameters

numerator?

number

Numerator of the ratio.

denominator?

number

Denominator of the ratio.

Returns

Ratio

Accessors

denominator

Get Signature

get denominator(): number

Returns the denominator of the ratio (that is, m from (n:m)).

Returns

number

Set Signature

set denominator(denominator): void

Sets the denominator of the ratio (that is, m from (n:m)).

The setter throws a RangeError if denominator is 0.

Parameters

denominator

number

Denominator of the ratio.

Returns

void


numerator

Get Signature

get numerator(): number

Returns the numerator of the ratio (that is, n from (n:m)).

Returns

number

Set Signature

set numerator(numerator): void

Sets the numerator of the ratio (that is, n from (n:m)).

Passing 0 is allowed but usually does not make practical sense.

Parameters

numerator

number

Numerator of the ratio.

Returns

void

Methods

clone()

clone(): Ratio

Creates a copy of the ratio.

Returns

Ratio


copy()

copy(other): this

Copies numerator and denominator from another ratio.

Parameters

other

Ratio

Ratio to copy.

Returns

this


toNumber()

toNumber(): number

Converts the ratio to a numeric value.

Returns

number