format widget - leading zero padding

1
  Hello, I'm trying to format the output of an integer with leading zeros but I'm not sure how to do this. Could you tell me the best way to do this please?   Thanks Adrian
asked
7 answers
4

Agree with Andrej. But I would not create a calculated attribute out of it. Make the attribute a String and add the leading zeros with a MF that calls the StringUtils.Leftpad function of CommunityCommons only when needed. 

Calculated attributes are not so good for performance, so I would steer away from it if possible.

answered
2

Hi Adrian,

IOP there is no simpler way to do this than adding a new calculated string attribute e.g. PaddedNumber. To set this string you can make use of th java actions StringLeftPad in the community commons - https://appstore.home.mendix.com/link/app/170/Mendix/Community-Commons-Function-Library

-Andrej

answered
1

You could try to create an input box where you can enter leading zero's. When you want to save the value, you have to count the leading zero's and save that in a new attribute. Whenever you load the widget and retrieve your value, you have to retrieve the leading zero's attribute as well and add the zero's. Both attributes will be in one entity of course.

For example: you enter 000123.

You save: '123' as your number integer value and '3' as your leading zero's integer value.

When loading the widget,  add 3 x 0 before 123.

I hope this helps you in a way.

answered
1

Hi Guys,

Sorry to bother you again. I'm a real newbie so apologies for all the noddy questions. :(

When I try to use the CommunityCommons:

 

I don't see StringUtils in the drop down list, could you tell me what I'm doing wrong?

Cheers

Adrian

answered
1

I got it to work - thanks for your help guys :)

answered
0

Thanks Robert :).

 

If the user is allowed to enter a number which ever way they like, is there a way to display the output of that value in a formatted way - something like %06d?

 

Should I consider using string fields for the output?

 

Thanks again

Adrian

 

answered
0

Thanks Andrej - I'll check that out. :)

answered