Silver lining rstring() from bizarre pad() behaviour

So, lack of substring has been a thing for a while and when making the beginner’s expression template for here I was looking at splitting minutes into digits and found
(floor(#Dm#/10)) and (#Dm#-((floor(#Dm#/10))*10))

Seems like the second can be simplified due to a limitation in pad().

I would expect pad(1,2)=01, pad(12,2)=12, pad(123,2)=123
Nope, the last is 23. As far as I am aware other coding languages with a pad function do not truncate the original string if longer than the specified pad value.

So for the second digit in minutes you just need (pad(#Dm#,1))

Shame about the actual pad thing, I can’t be bothered to work around that to save some lit pixels on AOD but ho hum.

1 Like

You can also use modulo (#Dm#%10) for the second digit

4 Likes

Good to know. Cheers. Should have thought of that one myself. It’s obvious now I see it.

3 Likes

On the pad() front, be sure to check your negative values when padding temperature.
(pad(#WCT#,3)) get’s twitchy for the 1st 9° sub zero. -4° gives 0-4. Fair enough, it’s just padding the whole string value. Worth a note though. I probably overcomplicated it due caffeine replacing sleep but went with $#WCT#<0?-:$$#WCT#<0?(pad(abs(#WCT#),2)):$$#WCT#>-1?(pad(#WCT#,3)):$

1 Like