Is it possible to format a number ("%3.1f" C style) in a auto-compute formula?

Hello,
I am building an app and when a user create a new entry I auto compute a column (client_code) from the content of a column (client_id). Here is an example of what I would like:
client_id = 8, client_code = HL2020-008
client_id = 18, client_code = HL2020-018
client_id = 158, client_code = HL2020-158

I can easly make the concatenation (โ€œHL2020โ€&client_id) however, I would like to format the number โ€œ8โ€ in โ€œ008โ€. So far, I made it with ifs blocks (if client_id<10, if client_id<100, if client_id<1000โ€ฆ) but I was wondering if there was a easier way of doing it.

Thank you very much,

Ryan

Solved Solved
0 2 947
1 ACCEPTED SOLUTION

Steve
Platinum 4
Platinum 4

%3.1f applied to 8 would give 8.0. You appear to want the equivalent of %03u, which would give 008.

AppSheet doesnโ€™t have a general-purpose formatting function. The TEXT() function does some formatting, but probably isnโ€™t what you want. For your need, I suggest the following:

CONCATENATE(
  [client_code],
  "-",
  RIGHT(("000" & [client_id]), 3)
)

If you always want client_id formatted as a three-digit number with leading zeros, you can set the columnโ€™s Numeric digits property to 3.

See also:



View solution in original post

2 REPLIES 2

Steve
Platinum 4
Platinum 4

%3.1f applied to 8 would give 8.0. You appear to want the equivalent of %03u, which would give 008.

AppSheet doesnโ€™t have a general-purpose formatting function. The TEXT() function does some formatting, but probably isnโ€™t what you want. For your need, I suggest the following:

CONCATENATE(
  [client_code],
  "-",
  RIGHT(("000" & [client_id]), 3)
)

If you always want client_id formatted as a three-digit number with leading zeros, you can set the columnโ€™s Numeric digits property to 3.

See also:



Hello,

Your line RIGHT((โ€œ000โ€ & [client_id]), 3) is very clever and works perfectly, thank you very much!

Top Labels in this Space