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.

Methods

setShowPlusSign

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

setShowThousandsSeparator

Sets whether the thousands grouping separator will be shown.

setThousandsSeparator

Sets an override character for the thousands separator character.

setUseDedicatedUnicodeCharacters

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

setUseUnicodeSuperSubscript

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

showPlusSign

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

showThousandsSeparator

Returns True if the thousands grouping separator will be shown.

thousandsSeparator

Returns any override for the thousands separator character.

useDedicatedUnicodeCharacters

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

useUnicodeSuperSubscript

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

Virtual Methods

In PyQGIS, only methods marked as virtual can be safely overridden in a Python subclass of QgsFractionNumericFormat. See the FAQ for more details.

setConfiguration

Sets the format's configuration.

Static Methods

doubleToVulgarFraction

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

toUnicodeSubscript

Converts numbers in an input string to unicode subscript equivalents.

toUnicodeSuperscript

Converts numbers in an input string to unicode superscript equivalents.

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