[QGIS-Developer] QGIS expression: Formatting numbers with leading zeros

Mathieu Pellerin nirvn.asia at gmail.com
Wed Jul 12 01:16:29 PDT 2017


Andreas,

I think you're looking for: lpad("my_number",n - length("my_number"),0)

Math

On Wed, Jul 12, 2017 at 3:02 PM, Neumann, Andreas <a.neumann at carto.net>
wrote:

> Hi,
>
> Is there a way in a QGIS expression to format numbers with leading zeros
> up to n places before the decimal point? E.g. 1 should be 00001, 10 should
> be 00010, etc.
>
> I would need this for correct sorting.
>
> I know, I could probably write a python expression, or something
> complicated with CASE WHEN, but I'd like to avoid that.
>
> Perhaps something is already existing?
>
> Andreas
>
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20170712/6f6cfde1/attachment.html>


More information about the QGIS-Developer mailing list