Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×
The Claris Museum: The Vault of FileMaker Antiquities at Claris Engage 2025! ×

This topic is 7269 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

My gut just tells me that before I write some crumby calculation, that someone out there has already written a nice concise calculation to do the following:

I need to print out dates with "text endings"

Posted

Hi Mark,

This works in my test file:

Let(

d = Day(date);

Case(

d = 1 or d = 21 or d = 31; d & "st";

d= 2 or d = 22; d & "nd";

d= 3 or d = 23; d & "rd";

d & "th"

)

)

I kept wanting to use Choose() since I see a pattern in the 1, 2 and 3 but I was unable to do so. I'm sure others will come up with something better and I doubt it's necessary to use Let() but it makes it looks shorter. wink.gif

I'm not always clear when Let() is a benefit or a hindrance, ie, uses more resources (by it's very being) than it saves in evaluation cycles. I assume since Day(date) must be evaluated (?) that it is good to use in this instance.

LaRetta smile.gif

Posted

LeRetta-

I don't know about any others - but yours worked perfectly. grin.gif

(As far as I can tell - and I had written out 1-31 with all their endings before I posted the question - your solution fits in every case.)

Amazing !!

(My secondary

Posted

Hi Mark,

No ... thank you! I realized that if we wanted this to work with larger numbers it would break (because I only accounted for up through 31). So now I have a new learning project ... extend indefinitely for all numbers.

Choose() would certainly help in that instance. Oh boy! A new learning toy because a pattern exists somehow! This is where Bob Weaver, Queue and the other Masters shine ... smile.gif

LaRetta

Posted

I don't have FMP 7 to hand, but try this:

The teens -- 11th, 12th ... 19th -- have to be watched out for, otherwise it's pretty straight forward.

This function will work for dates no problem since thew max is 31. However should it be applied to any number, the formula needs another variable that considers the last two digits of the number.

Let(

d = Day(date);

Case(

d > 10 and d < 20 ; d & "th";

Right( d ; 2 ) = 1 ; d & "st";

Right( d ; 2 ) = 2 ; d & "nd";

Right( d ; 2 ) = 3 ; d & "rd";

d & "th"

)

)

Posted

Did I hear someone mention my name?

Okay, how about this:

Let(d=Day(Date);

d&Choose(Min(4;Mod(d;10));"th";"st";"nd";"rd";"th"))

<Edit>

Oops, Vaughan posted while I was writing this and I forgot about the 11th 12th 13th etc., so ignore the above. Here is fixed version:

Let(d=Day(Date);

d&Choose(Min(4;Mod(d;10))*((d<11) or (d>13));"th";"st";"nd";"rd";"th"))

Posted

Hi Vaughan!!

The teens -- 11th, 12th ... 19th -- have to be watched out for...

Boy, isn't that always the truth. wink.gif

Well, I love your theory and will incorporate it. But it breaks on the 22nd, making it 22th. And that makes NO SENSE!!! None! I miss the logic of that break. In fact, 21, 22, 23 and 31 break. Illogical.

Is it because FM thinks Day() is a number? I'm perplexed.

Oh Bob!!! Yep, you heard your name!!! Choose() YES YES!! Well, now I won't sleep until I figure this puppy out! But don't anyone wait for me - I'm new and slow on these things (and sometimes flat-out fail) ... but I learn so DARNED MUCH when I do them myself!!

First one to solve it gets an 'Atta Boy'! smile.gif

LaRetta

Posted

Shoukld be this:

Let(

d = Day(date);

Case(

d > 10 and d < 20 ; d & "th";

Right( d ; 1 ) = 1 ; d & "st";

Right( d ; 1 ) = 2 ; d & "nd";

Right( d ; 1 ) = 3 ; d & "rd";

d & "th"

)

)

Posted

Geez Louise, Bob!

I only got as far as, "What the heck is Mod() doing in there?"

Well, good thing ... because I have a project to finish tonight. Oh, but I'm going to pick this puppy apart first, you can bet on that! Thank you! smile.gif

Oh, isn't Choose() sweet. smile.gif

LaRetta

Posted

Okay Bob! Using a Number field, this works on MOST numbers ... 452nd, 123rd - even 6473rd.

It breaks on number 111 making it 111st.

Vaughan, yes, the adjustment worked. Ooops, yours also breaks on 111. But I haven't even left the starting gate - I'm still stuck on understanding the logic of Bob's calculation. crazy.gif

Choose() would certainly be more efficient than Case() if the sequence can be consistent.

I swear this stuff is better than sex; well ... almost. smile.gif

LaRetta

Posted

I did a calculation which will take any number and output its text representation, but I never did ordinal suffixes...

I.e. 1 --> One, 12 --> Twelve, 362 --> Three Hundred Sixty Two, 7777 --> Seven Thousand Seven Hundred Seventy Seven.

Actually, I did it first in javascript, then I did it again in applescript, and finally recreated it in a Filemaker calculation.

One of the versions would handle any number from zero to about 29 or 30 DIGITS. The FM version is much more limited.

Posted

(Untested)

Let ( [

Tens = Int ( Mod ( Input ; 100 ) / 10 ) ;

Units = Int ( Mod (Input ; 10 ) )

] ;

Int ( Input ) &

Choose ( Tens = 1 ;

Choose ( Units < 4 ; "th" ;

Choose ( 3 - Units ; "rd" ; "nd" ; "st "; "th" ) ; )

"th" )

)

Posted

Comment,

I can go to bed now. You beat me to it but not by much. I've been working on it for only 6 hours ... how long did it take you? 10 minutes? I'd have gotten it sooner or later. crazy.gif

Oh. And it even makes total sense to me (after I read yours, of course). grin.gif

You split it; you split the pattern. I didn't think of that; I thought of it as linear; probably never would have thought of splitting it. I just spent 45 minutes trying to break it - there are no breaks. Untested? Good grief, it has been now.

Well, I discovered a thousand things that didn't work (and that was quite exciting)! And I still need to understand Bob's thinking on his. I also discovered cool new things about some number functions that blow my mind, so I'm doubly tickled today.

THANK YOU and night night. wink.gif

Oh. No ATTA BOY emoticons on here, sorry. But you sure earned one.

LaRetta

Posted

I didn't bother to make mine work for numbers over 31 since it was intended for days of the month, but my earlier one could be changed to the following to work with any number:

Let([d=MyNumber; n=Mod(d;100)];

d&Choose(Min(4;Mod(n;10))*((n<11) or (n>13));"th";"st";"nd";"rd";"th"))

Posted

It works pretty as a peach - of course! I suppose it took you 10 minutes also.

Bob, can you explain this part? My mind doesn't follow it at all ...

*((n<11) or (n>13))

I figure it will take a century to reach this level of understanding. Oh well, nothing I'd rather be doing anyway.

LaRetta smile.gif

Posted

If n is less than 11 or greater than 13 then the result is 1 and when multiplied by the previous term Min(4;Mod(n;10)), it gives the values 0-4 to pick the appropriate suffix. If n is in the range 11-13, then the result is zero and forces the whole calculation to zero thus producing a suffix of "th" for the teens.

Posted

If n is less than 11 or greater than 13 then the result is 1 and when multiplied by the previous term Min(4;Mod(n;10)), it gives the values 0-4 to pick the appropriate suffix. If n is in the range 11-13, then the result is zero and forces the whole calculation to zero thus producing a suffix of "th" for the teens.

Posted

If n is less than 11 or greater than 13 then the result is 1 and when multiplied by the previous term Min(4;Mod(n;10)), it gives the values 0-4 to pick the appropriate suffix. If n is in the range 11-13, then the result is zero and forces the whole calculation to zero thus producing a suffix of "th" for the teens.

Posted

LaRetta: I stated earlier that my calc would only work for numbers up to 31... I predicted it'd break at 111, glad you confirmed it for me. wink.gif

If the calc works up to 120 (just past the 100+teens) then it should be good for all values, since the pattern doesn't change. Well, maybe cheack 200+teens amd make sure it works there too.

Posted

LaRetta: I stated earlier that my calc would only work for numbers up to 31... I predicted it'd break at 111, glad you confirmed it for me. wink.gif

If the calc works up to 120 (just past the 100+teens) then it should be good for all values, since the pattern doesn't change. Well, maybe cheack 200+teens amd make sure it works there too.

Posted

LaRetta: I stated earlier that my calc would only work for numbers up to 31... I predicted it'd break at 111, glad you confirmed it for me. wink.gif

If the calc works up to 120 (just past the 100+teens) then it should be good for all values, since the pattern doesn't change. Well, maybe cheack 200+teens amd make sure it works there too.

This topic is 7269 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.