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
- rtype
QgsNumericFormat
- param context
- param configuration
Converts a double
value
to a vulgar fraction (e.g.- param value
- rtype
str
Sets the format’s
configuration
.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
True
if a leading plus sign will be shown for positive values.Returns
True
if the thousands grouping separator will be shown.- rtype
int
- rtype
float
Returns any override for the thousands separator character.
Converts numbers in an
input
string to unicode subscript equivalents.Converts numbers in an
input
string to unicode superscript equivalents.Returns
True
if dedicated unicode characters should be used, when the are available for the particular fraction (e.g.Returns
True
if unicode superscript and subscript characters should be used, (e.g.- rtype
str
- clone(self) → QgsNumericFormat¶
- Return type
- 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
configuration (Dict[str) –
context (QgsReadWriteContext) –
- Return type
- 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 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) – acceptable tolerance. Larger values will give “nicer” fractions.
- Return type
Tuple[bool, int, int, int]
- Returns
True
ifvalue
was successfully converted to a fractionnumerator: 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
value (float) –
context (QgsNumericFormatContext) –
- Return type
str
- id(self) → str¶
- Return type
str
- setConfiguration(self, configuration: Dict[str, Any], context: QgsReadWriteContext)¶
Sets the format’s
configuration
.- Parameters
configuration (Dict[str) –
context (QgsReadWriteContext) –
- setShowPlusSign(self, show: bool)¶
Sets whether a leading plus sign will be shown for positive values.
See also
- Parameters
show (bool) –
- setShowThousandsSeparator(self, show: bool)¶
Sets whether the thousands grouping separator will be shown.
See also
- 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.See also
- 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. ½, ¼).
See also
See also
- Parameters
enabled (bool) –
- setUseUnicodeSuperSubscript(self, enabled: bool)¶
Sets whether unicode superscript and subscript characters should be used, (e.g. “⁶/₇”).
See also
See also
- Parameters
enabled (bool) –
- showPlusSign(self) → bool¶
Returns
True
if a leading plus sign will be shown for positive values.See also
- Return type
bool
- showThousandsSeparator(self) → bool¶
Returns
True
if the thousands grouping separator will be shown.See also
- 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.
See also
- Return type
str
- toUnicodeSubscript(input: str) → str¶
Converts numbers in an
input
string to unicode subscript equivalents.See also
- Parameters
input (str) –
- Return type
str
- toUnicodeSuperscript(input: str) → str¶
Converts numbers in an
input
string to unicode superscript equivalents.See also
- 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. ½, ¼).See also
See also
- Return type
bool
- useUnicodeSuperSubscript(self) → bool¶
Returns
True
if unicode superscript and subscript characters should be used, (e.g. “⁶/₇”).See also
See also
- Return type
bool
- visibleName(self) → str¶
- Return type
str