Is there an easy way in .NET to get “st”, “nd”, “rd” and “th” endings for numbers? [duplicate]

It’s a function which is a lot simpler than you think. Though there might be a .NET function already in existence for this, the following function (written in PHP) does the job. It shouldn’t be too hard to port it over. function ordinal($num) { $ones = $num % 10; $tens = floor($num / 10) % … Read more

Ordinal numbers replacement

The package number-parser can parse ordinal words (“first”, “second”, etc) to integers. from number_parser import parse_ordinal n = parse_ordinal(“first”) To convert an integer to “1st”, “2nd”, etc, you can use the following: def ordinal(n: int): if 11 <= (n % 100) <= 13: suffix = ‘th’ else: suffix = [‘th’, ‘st’, ‘nd’, ‘rd’, ‘th’][min(n % … Read more

Is there an easy way to create ordinals in C#?

This page gives you a complete listing of all custom numerical formatting rules: Custom numeric format strings As you can see, there is nothing in there about ordinals, so it can’t be done using String.Format. However its not really that hard to write a function to do it. public static string AddOrdinal(int num) { if( … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)