How to Preserve Leading Zeros When Converting calculate Randomstring to Number in Bubble?

I’m using Bubble’s calculate Randomstring


operator to generate an 8-digit value, and by default it comes through as text. I need to store it as a numeric value, so I’m applying “Converted to number.” However, whenever the random string begins with a zero, the leading zero is dropped and I end up with a 7-digit number.

My requirement is to always have exactly 8 digits, even in number format. With the “Converted to number” step (see attached screenshot), it never produces a zero in the first position—it always starts at 1.

Is there a way to configure this so that the generated number can include a leading zero when stored as a number, guaranteeing an 8-digit value every time?

Hey there! Unfortunately, as far as I know, you can’t save numbers with a leading zero like 054 since they’ll be treated as regular integers and lose the zero.

But since it’s a verification code, you can store it as a string instead. So in any input field, you can simply convert the number to a string, which is a much easier and more reliable approach.