Class: QgsNumericFormat

A numeric formatter allows for formatting a numeric value for display, using a variety of different formatting techniques (e.g. as scientific notation, currency values, percentage values, etc)

This is an abstract base class and will always need to be subclassed.

Added in version 3.12.

Class Hierarchy

Inheritance diagram of qgis.core.QgsNumericFormat

Subclasses

QgsBasicNumericFormat

A numeric formatter which returns a simple text representation of a value.

QgsExpressionBasedNumericFormat

A numeric formatter which uses a QgsExpression to calculate the text representation of a value.

QgsFallbackNumericFormat

A basic numeric formatter which returns a simple text representation of a value.

QgsFractionNumericFormat

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

Methods

clone

Clones the format, returning a new object.

configuration

Returns the current configuration of the formatter.

create

Creates a new copy of the format, using the supplied configuration.

formatDouble

Returns a formatted string representation of a numeric double value.

id

Returns a unique id for this numeric format.

sortKey

Returns a sorting key value, where formats with a lower sort key will be shown earlier in lists.

suggestSampleValue

Returns a suggested sample value which nicely represents the current format configuration.

visibleName

Returns the translated, user-visible name for this format.

writeXml

Writes the format to an XML element.

class qgis.core.QgsNumericFormat[source]

Bases: object

clone(self) QgsNumericFormat | None[source]

Clones the format, returning a new object.

The caller takes ownership of the returned object.

Return type:

Optional[QgsNumericFormat]

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

Returns the current configuration of the formatter. This value can be used in a call to create() in order to recreate this formatter in its current state.

Parameters:

context (QgsReadWriteContext)

Return type:

Dict[str, Any]

create(self, configuration: Dict[str, Any], context: QgsReadWriteContext) QgsNumericFormat | None[source]

Creates a new copy of the format, using the supplied configuration.

The caller takes ownership of the returned object.

Parameters:
Return type:

Optional[QgsNumericFormat]

formatDouble(self, value: float, context: QgsNumericFormatContext) str[source]

Returns a formatted string representation of a numeric double value.

Parameters:
Return type:

str

id(self) str[source]

Returns a unique id for this numeric format.

This id is used to identify this numeric format in the registry with QgsNumericFormatRegistry.format().

Return type:

str

sortKey(self) int[source]

Returns a sorting key value, where formats with a lower sort key will be shown earlier in lists.

Generally, subclasses should return QgsNumericFormat.sortKey() as their sorting key.

Return type:

int

suggestSampleValue(self) float[source]

Returns a suggested sample value which nicely represents the current format configuration.

Return type:

float

visibleName(self) str[source]

Returns the translated, user-visible name for this format.

Return type:

str

writeXml(self, element: QDomElement, document: QDomDocument, context: QgsReadWriteContext)[source]

Writes the format to an XML element.

Parameters: