Pike v8.1 release 6

Method Gmp.mpq()->get_string()


Method get_string

string get_string(void|int decimal_fraction)

Description

If decimal_fraction is zero or left out, the number is returned as a string on the form "numerator/denominator", where both parts are decimal integers. The numerator may be negative, but the denominator is always positive.

If decimal_fraction is set, then the number is returned as a (possibly negative) decimal fraction, i.e. a decimal number with a decimal point somewhere inside. There is always at least one digit before and after the decimal point.

If the number can be accurately described that way, i.e. without an infinite number of decimals, then no denominator is included. Otherwise the remaining denominator is added to the decimal fraction after a "/". For example, 4711/100 is returned as "47.11", 4711/200 as "23.555", and 4711/300 as "47.11/3".

If decimal_fraction is 1 then the decimal fraction contains a '.' only if there are decimals in it. If it is 2 or higher then the decimal fraction always contains a '.' with at least one digit before and after it.

Note

In any case, there are no unnecessary padding zeroes at the beginning or end of any decimal number.