Numeric formatting in apps for numbers and integers

Hi All,

I’m working on an app that involves serial numbers, and I’m parsing numbers out of text IDs using the Text To Number expression. The issue I’m having is I would like the number to always be three digits, so if the number parsed is 3, I would like it to be 003, 040 for 40, etc. Is there a way to specify numeric format, either in the expression editor or in another trigger step?

Thanks!

Hey @kcolwell ,

Sorry for the delay getting back to you here - Took a little digging to get a good answer on this one.

The short answer is: 030 and 30 are the same number, and so they will be automatically truncated when being stored. The workaround is to use a text field as opposed to a number field.

The long answer: While we could enable you to be able to adjust how numbers are displayed, when we go to store them to the databases where your Tulip data is stored, they would be truncated back to 30 (from 030). What this means is if you stored your 030 to a table, and then reloaded it, it would be 30 again. This is an inherent property of a number in sql. The solution on our end would be to store everything as text, and track what type a user has selected, and cast back to that type before you use it. This is possible, but a fairly large data architecture change.

Is there a reason you need your number without leading zeroes removed (and cant use it as text)?

Pete

Hi @kcolwell I’ve developed something that solves the issue you describe, but it’ll be a bit difficult to extract from the rest of the code of my app, so unfortunately I can only say it is possible to solve the issue you face haha. I store the number as text in the tulip table, and have created a “three digit solver” that involves looping within Tulip. In my case I’m creating a bank of serial numbers starting from standard integers (1, 2, 3, etc.) and turning those into the three digit versions you describe. This works fine for us but, as I said does involve using looping within Tulip. If you haven’t done any looping I’d start with this post Quick tips - Looping! And I can provide some more details from there if you are interested / run into roadblocks in your own development

Hi @Pete_Hartnett and @Ethan,

Thanks for your replies! I am using this for id generation. My app concatenates a series of parameters to create an id. Some parameters are numbers, and sometimes a parameter will be between one and ten, sometimes 10 and 100, sometimes over 100, but I want that part of the id to always be three digits, so every serial number is the same length. I was hoping for some sort of numeric formatting so that when I create my serial number string I would just specify the format and it would do the work for me. I’ve done something similar in other programming languages.

I managed to find a work around using something which sounds similar to what Ethan is doing. It all works fine, numeric formatting would just save me some steps.

Thanks again!

Another method of accomplishing this would be to just transform the number while creating the record id. For example, you could use the expression editor to do it (provided it will never be more than 3 digits)

left('000', 3 - len(@Variable.number  + '')) + @Variable.number 

2 Likes