[QGIS-Developer] QGIS expression: Formatting numbers with leading zeros
Neumann, Andreas
a.neumann at carto.net
Wed Jul 12 01:54:38 PDT 2017
Hi Matthieu,
It works, but slightly simpler ;-)
We don't need the calculation "n-length("my_number"), because the second
parameter is the total string length.
Anyway, it works now for me and it is rather easy with lpad.
Thanks,
Andreas
On 2017-07-12 10:16, Mathieu Pellerin wrote:
> 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 [1]
>> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer [1]
Links:
------
[1] 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/c521f2dd/attachment-0001.html>
More information about the QGIS-Developer
mailing list