Class: QgsFractionNumericFormat

A numeric formatter which returns a vulgar fractional representation of a decimal value (e.g. “1/2” instead of 0.5).

Added in version 3.14.

Class Hierarchy

Inheritance diagram of qgis.core.QgsFractionNumericFormat

Base classes

QgsNumericFormat

Abstract base class for numeric formatters, which allow for formatting a numeric value for display.

class qgis.core.QgsFractionNumericFormat[source]

Bases: QgsNumericFormat

__init__()

Default constructor

__init__(a0: QgsFractionNumericFormat)
Parameters:

a0 (QgsFractionNumericFormat)

static doubleToVulgarFraction(value: float, tolerance: float = 1e-10)[source]

Converts a double value to a vulgar fraction (e.g. ⅓, ¼, etc) by attempting to calculate the corresponding numerator and denominator, within the specified tolerance.

This method is based of Richard’s algorithm (1981) from “Continued Fractions without Tears” (University of Minnesota).

Parameters:
  • value (float) – input value to convert

  • tolerance (float = 1e-10) -> (bool) – acceptable tolerance. Larger values will give “nicer” fractions.

Returns:

  • True if value was successfully converted to a fraction

  • numerator: calculated fraction numerator

  • denominator: the calculated fraction denominator

  • sign: the sign of the result (as -1 or +1 values)

virtual setConfiguration(self, configuration: Dict[str, Any], context: QgsReadWriteContext)[source]

Sets the format’s configuration.

Parameters:
setShowPlusSign(self, show: bool)[source]

Sets whether a leading plus sign will be shown for positive values.

See also

showPlusSign()

Parameters:

show (bool)

setShowThousandsSeparator(self, show: bool)[source]

Sets whether the thousands grouping separator will be shown.

Parameters:

show (bool)

setThousandsSeparator(self, character: str)[source]

Sets an override character for the thousands separator character. If an invalid QChar is set, then the QGIS locale separator is used instead.

Parameters:

character (str)

setUseDedicatedUnicodeCharacters(self, enabled: bool)[source]

Sets whether dedicated unicode characters should be used, when the are available for the particular fraction (e.g. ½, ¼).

Parameters:

enabled (bool)

setUseUnicodeSuperSubscript(self, enabled: bool)[source]

Sets whether unicode superscript and subscript characters should be used, (e.g. “⁶/₇”).

Parameters:

enabled (bool)

showPlusSign(self) bool[source]

Returns True if a leading plus sign will be shown for positive values.

Return type:

bool

showThousandsSeparator(self) bool[source]

Returns True if the thousands grouping separator will be shown.

Return type:

bool

thousandsSeparator(self) str[source]

Returns any override for the thousands separator character. If an invalid QChar is returned, then the QGIS locale separator is used instead.

Return type:

str

static toUnicodeSubscript(input: str | None) str[source]

Converts numbers in an input string to unicode subscript equivalents.

Parameters:

input (Optional[str])

Return type:

str

static toUnicodeSuperscript(input: str | None) str[source]

Converts numbers in an input string to unicode superscript equivalents.

Parameters:

input (Optional[str])

Return type:

str

useDedicatedUnicodeCharacters(self) bool[source]

Returns True if dedicated unicode characters should be used, when the are available for the particular fraction (e.g. ½, ¼).

Return type:

bool

useUnicodeSuperSubscript(self) bool[source]

Returns True if unicode superscript and subscript characters should be used, (e.g. “⁶/₇”).

Return type:

bool