Class: QgsFractionNumericFormat

class qgis.core.QgsFractionNumericFormat

Bases: QgsNumericFormat

Default constructor

QgsFractionNumericFormat(QgsFractionNumericFormat)

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

Methods

clone

rtype

QgsNumericFormat

configuration

param context

create

param configuration

doubleToVulgarFraction

Converts a double value to a vulgar fraction (e.g.

formatDouble

param value

id

rtype

str

setConfiguration

Sets the format’s configuration.

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.

sortKey

rtype

int

suggestSampleValue

rtype

float

thousandsSeparator

Returns any override for the thousands separator character.

toUnicodeSubscript

Converts numbers in an input string to unicode subscript equivalents.

toUnicodeSuperscript

Converts numbers in an input string to unicode superscript equivalents.

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.

visibleName

rtype

str

clone(self)QgsNumericFormat
Return type

QgsNumericFormat

configuration(self, context: QgsReadWriteContext)Dict[str, Any]
Parameters

context (QgsReadWriteContext) –

Return type

Dict[str, Any]

create(self, configuration: Dict[str, Any], context: QgsReadWriteContext)QgsNumericFormat
Parameters
Return type

QgsNumericFormat

doubleToVulgarFraction(value: float, tolerance: float = 1e-10)Tuple[bool, int, int, int]

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) – acceptable tolerance. Larger values will give “nicer” fractions.

Return type

Tuple[bool, int, int, int]

Returns

  • True if value was successfully converted to a fraction

  • numerator: will be set to calculated fraction numerator

  • denominator: will be set to the calculated fraction denominator

  • sign: will be set to the sign of the result (as -1 or +1 values)

formatDouble(self, value: float, context: QgsNumericFormatContext)str
Parameters
Return type

str

id(self)str
Return type

str

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

Sets the format’s configuration.

Parameters
setShowPlusSign(self, show: bool)

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

See also

showPlusSign()

Parameters

show (bool) –

setShowThousandsSeparator(self, show: bool)

Sets whether the thousands grouping separator will be shown.

Parameters

show (bool) –

setThousandsSeparator(self, character: str)

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)

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)

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

Parameters

enabled (bool) –

showPlusSign(self)bool

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

Return type

bool

showThousandsSeparator(self)bool

Returns True if the thousands grouping separator will be shown.

Return type

bool

sortKey(self)int
Return type

int

suggestSampleValue(self)float
Return type

float

thousandsSeparator(self)str

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

toUnicodeSubscript(input: str)str

Converts numbers in an input string to unicode subscript equivalents.

Parameters

input (str) –

Return type

str

toUnicodeSuperscript(input: str)str

Converts numbers in an input string to unicode superscript equivalents.

Parameters

input (str) –

Return type

str

useDedicatedUnicodeCharacters(self)bool

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

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

Return type

bool

visibleName(self)str
Return type

str