4 Replies Latest reply on Sep 3, 2009 12:33 PM by RickWhitelaw

# Custom function quirk

### Title

Custom function quirk

### Post

Hi,

I have a function that's meant to pad a number with leading zeroes including numbers with one or more decimals. Here's the function:

Right( "0000000000000000000000" & Number ; If ( Length ( Number )    ≠    Filter ( Number ; "0123456789");Digits+Abs(Length ( Number )- Length ( Filter ( Number ; "0123456789") ) );Digits ) )

//end function

The variables are "number" and "digits" (the total number of digits needed). The function seems to work perfectly. If "digits" is set to 6, 20 evaluates as "000020", .31 to

"0000.31", 23.2.1 to "0023.2.1" etc. In other words, regardless of decimal points (or any non-numeric character) included in the original number, the function retains the decimals but adds the proper number of numeric characters. I was testing this out and found an odd exception. ".2" evaluates as "0000.2" if digits is set to 6, "00000.2" if digits is set to 7. This is odd. .3 works as does every other number I've tried. .20 works. What strikes me as odd is that the function doesn't do numeric evaluation (except for the obvious wrapped in "Abs"). It's primarily a text function. There should be no difference between ".1" and ".2" (in terms of Length)yet they evaluate differently. I may be missing something obvious, and this function may have "limited" utility, but the odd exception intrigues me.

The syntax would be "Pad Zeroes for Decimal Numbers(number;digits) ". In the function, everything from the "If" onwards is an expression of "digits".

• ###### 1. Re: Custom function quirk

RickWhitelaw wrote:

If ( Length ( Number )    ≠    Filter ( Number ; "0123456789");

Shouldn't that be:

Length ( Number ) ≠ Length ( Filter ( Number ; "0123456789") )

• ###### 2. Re: Custom function quirk

Comment,

That was it. Thanks. I WAS missing something obvious! This is a good example of when , even with an obvious omission, something can work MOST of the time. If this function performed something crucial it would have turned around and bit me sooner or later. I'm still not clear why ".2" was the only number I found that didn't work, or why other numbers evaluated correctly with a significant fault in the function, but it's less important than getting it to work as it should.

RW

• ###### 3. Re: Custom function quirk

RickWhitelaw wrote:
I'm still not clear why ".2" was the only number I found that didn't work

It's a coincidence: The length of ".2" is 2, and so is the result of the Filter().

BTW, I am still not quite sure what your function is supposed to do - couldn't it be written simply as =

`Left ( "0000000000000000000000" ;  Digits - Length ( Filter ( Number ; "0123456789" ) ) ) & Number`

• ###### 4. Re: Custom function quirk

"It's a coincidence: The length of ".2" is 2, and so is the result of the Filter()"

Of course! The added Length( ) takes care of that. The original WAS evaluating a numerical value and shouldn't have been. I have no use for the function and had written it for someone else. In most of what I do the number of characters is more important than the number of numerical characters. Anyway . . . mystery solved.