Check out the first Dataiku 8 Deep Dive focusing on Productivity on October 29th Read More

How to pad a number with leading zeros

How to pad a number with leading zeros

A common requirement when you have a column of numbers is to format all numbers so that they have the same length, adding leading zeros if needed.

This can be done in the DSS preparation recipe using a Formula.

The formula function to use is format. For example, to ensure that all values of the column mycolumn are padded to have a length of 11, including leading zeros, use: format("%011d", mycolumn)



It is useful to remember the usual formula rules to refer the values of columns, as described in the DSS reference documentation

For example, to do the same in a column named "my column" (note the space), you would use instead format("%011d", numval("my column"))

format is actually a very powerful function that uses Java string formatting capabilities.  See this Java reference for more details.

Level 1

easy way to solve headache issue if you do not see artical


This will be super helpful for USA postal codes / zip codes that have been turned to integers and truncated some where in the data process prior to getting into dss.  

Getting leading 0s back in place for the north eastern United States can be sort of a pain.  This should help a lot. 

Labels (3)
Version history
Revision #:
3 of 3
Last update:
‎03-30-2020 04:38 PM
Updated by: