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¶
Base classes¶
Abstract base class for numeric formatters, which allow for formatting a numeric value for display. |
Methods
Sets whether a leading plus sign will be shown for positive values. |
|
Sets whether the thousands grouping separator will be shown. |
|
Sets an override character for the thousands separator character. |
|
Sets whether dedicated unicode characters should be used, when the are available for the particular fraction (e.g. ½, ¼). |
|
Sets whether unicode superscript and subscript characters should be used, (e.g. "⁶/₇"). |
|
Returns |
|
Returns |
|
Returns any override for the thousands separator character. |
|
Returns |
|
Returns |
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.
Sets the format's configuration. |
Static Methods
Converts a double value to a vulgar fraction (e.g. ⅓, ¼, etc) by attempting to calculate the corresponding numerator and denominator, within the specified tolerance. |
|
Converts numbers in an input string to unicode subscript equivalents. |
|
Converts numbers in an input string to unicode superscript equivalents. |
- class qgis.core.QgsFractionNumericFormat[source]¶
Bases:
QgsNumericFormat
- __init__()
Default constructor
- __init__(a0: QgsFractionNumericFormat)
- Parameters:
- 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 correspondingnumerator
anddenominator
, within the specifiedtolerance
.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
ifvalue
was successfully converted to a fractionnumerator: 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:
configuration (Dict[str, Any])
context (QgsReadWriteContext)
- setShowPlusSign(self, show: bool)[source]¶
Sets whether a leading plus sign will be shown for positive values.
See also
- Parameters:
show (bool)
- setShowThousandsSeparator(self, show: bool)[source]¶
Sets whether the thousands grouping separator will be shown.
See also
- 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.See also
- 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. ½, ¼).
See also
See also
- Parameters:
enabled (bool)
- setUseUnicodeSuperSubscript(self, enabled: bool)[source]¶
Sets whether unicode superscript and subscript characters should be used, (e.g. “⁶/₇”).
See also
See also
- Parameters:
enabled (bool)
- showPlusSign(self) bool [source]¶
Returns
True
if a leading plus sign will be shown for positive values.See also
- Return type:
bool
- showThousandsSeparator(self) bool [source]¶
Returns
True
if the thousands grouping separator will be shown.See also
- 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.
See also
- Return type:
str
- static toUnicodeSubscript(input: str | None) str [source]¶
Converts numbers in an
input
string to unicode subscript equivalents.See also
- Parameters:
input (Optional[str])
- Return type:
str
- static toUnicodeSuperscript(input: str | None) str [source]¶
Converts numbers in an
input
string to unicode superscript equivalents.See also
- 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. ½, ¼).See also
See also
- Return type:
bool