Fixed Field Legnth

Meeting place for R&R customers and clients to share tips and ideas. Post your questions, messages or problems here.
Post Reply
Marfabend
Posts: 0
Joined: Fri Feb 16, 2018 2:30 pm

Fixed Field Legnth

Post by Marfabend » Fri Aug 29, 2008 10:21 am

I have a numeric field that I want to export from R&R with a fixed legnth 6 digits, decimal point, five digits. If there are not 6 digits in front of the decimal, I would like it padded with zeros. Can you tell me how to set this up?

kfleming
Posts: 5795
Joined: Tue Oct 10, 2017 12:44 pm

=> RE: Fixed Field Legnth

Post by kfleming » Tue Sep 02, 2008 10:44 am

You could use the expression:__replicate("0",12-len(ltrim(str(NumField,12,5))))+ltrim(str(NumField,12,5))____where NumField is the name of a numeric field__to have 49.95 appear as 000049.95000____Kathleen__R&R Support

Fonz
Posts: 10
Joined: Tue Oct 10, 2017 12:44 pm

==> RE: Fixed Field Legnth

Post by Fonz » Fri Sep 26, 2008 9:08 am

Here is an alternative:__If you want a number to have a fixed width with leading zeros, then you need to ADD to this number, the value of ONE (1) with AS MANAY ZEROS as the required width. Next you use the RIGHT Function to get your 6 characters from the right. So the formula is:____RIGHT(Str(YourNum + 1,000,000),6) - for 6 character width ____Example : YourNum = 376 and you want to display "000376" . Then:__Right(Str(376+1,000,000),6) = ^000376^____Note: Str(376+1000000) wiil evaluate to "1000376" - a 7 digit number and taking as manay desired characters as match the zeros from the RIGHT will drop the ^1^ always.____If the width required is 5, then__RIGHT(Str(100,000+376 = 100376),5) = ^00376^____If the width required is 10, then:__RIGHT(Str(10,000,000,000 + 376 = 10000000376),10) = ^0000000376^____Regards__Mark

Fonz
Posts: 10
Joined: Tue Oct 10, 2017 12:44 pm

===> RE: Fixed Field Legnth

Post by Fonz » Fri Sep 26, 2008 12:38 pm

With my suggestion above, the RIGHT function becomes more complicated should your number not be an Integer value; you will then need to work out the number of places after the decimal and add them, PLUS 1 (for the decimal point) to the RIGHT function extract e.g.____RIGHT( STR(1000000 + ROUND(376,3)),6+3+1) ____EVALUTES TO:__RIGHT( STR(1000000 + 376.000),10) ____EVALUTES TO:__000376.000____However, whenever I have used leading zeros in the past, it has always been in a ^Code^ field (e.g. Employee Payroll No) and these Codes are generally integers - in those cases, my first solution applies without the ROUND function.____Cheers__Mark______

Post Reply