Brian Dunning's FileMaker Custom Functions

LeadingZeros ( value, numDigits )

Converts any number into a string and pads the number with leading zeros until the number of required digits is achieved.

  Be the first to rate this function Log in to vote

Kyle Williams   Kyle Williams - Show more from this author
Augusto Digital
https://www.youtube.com/channel/UCpJlB7cmVNMjbjgY96MEsng

  Sample input:
LeadingZeros( 355, 1 )
LeadingZeros( 355, 8 )
  Sample output:
355
00000355

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

Converts any number into a string and pads the number with leading zeros until the number of required digits is achieved.

 

Comments

Dan Shockley   Dan Shockley
May 28, 2025
You could replace the hard-coded string of zeroes with this:
Right ( GetAsText ( 10^numDigits ) ; numDigits )

I think that's a trick I first saw in the custom function CustomList by Agnes Barouh.
 
Dan Shockley   Dan Shockley
May 28, 2025
Update: I should have said to use this, to avoid getting scientific notation for large numbers:
Right ( NumToJText ( 10^numDigits ; "" ; "" ) ; numDigits )
 
Kyle Williams   Kyle Williams, Augusto Digital
May 28, 2025
@Dan, both of your formulas are missing the values..

Using Right ( NumToJText ( 10^numDigits & value; "" ; "" ) ; numDigits )

I was able to get this to work with up to 8 leading zeros but after that it just returns "?".. This issue is probably due to the scientific notation issues.
 
Kyle Williams   Kyle Williams, Augusto Digital
May 28, 2025
Update... This could work to replace all of the zeros, however, it does start with a leading one but would work great for most cases:

NumToJText ( 10^100 ; "" ; "" )
 
Kyle Williams   Kyle Williams, Augusto Digital
May 28, 2025
Here is the formula with Dan Shockley's suggested update:

GetAsText( Right( NumToJText ( 10^100 ; "" ; "" ) & GetAsText(value); Max( numDigits; Length(value)) ))
 

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 21 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: