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.neum...@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@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
_______________________________________________
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to