print(ordinal(32)) # 32nd

时间:2023-07-04    发布者:    浏览次数:2027

分享到:

确实是个常见的英文序数词错误。正确写法是 32nd,不是 32th。

两位一律用\n

快速规则

  • 先看最后两位:11、12、13 一律用 th(11th, 12th, 13th)
  • 否则看个位:
    • 1 → st(1st, 21st, 31st)
    • 2 → nd(2nd, 22nd, 32nd)
    • 3 → rd(3rd, 23rd, 33rd)
    • 其他 → th(4th, 24th, 34th)

举例

  • 1st, 2nd, 3rd, 4th
  • 11th, 12th, 13th
  • 21st, 22nd, 23rd, 24th
  • 31st, 32nd, 33rd, 34th

如果要避免再出错,可以在出图前用小工具自动生成后缀。示例代码:

Python

def ordinal(n: int) -[[NEWS.CONTENT_HTML]]gt; str:    if 10 [[NEWS.CONTENT_HTML]]lt;= n % 100 [[NEWS.CONTENT_HTML]]lt;= 13:        suf = [[NEWS.CONTENT_HTML]]quot;th[[NEWS.CONTENT_HTML]]quot;    else:        suf = {1: [[NEWS.CONTENT_HTML]]quot;st[[NEWS.CONTENT_HTML]]quot;, 2: [[NEWS.CONTENT_HTML]]quot;nd[[NEWS.CONTENT_HTML]]quot;, 3: [[NEWS.CONTENT_HTML]]quot;rd[[NEWS.CONTENT_HTML]]quot;}.get(n % 10, [[NEWS.CONTENT_HTML]]quot;th[[NEWS.CONTENT_HTML]]quot;)    return f[[NEWS.CONTENT_HTML]]quot;{n}{suf}[[NEWS.CONTENT_HTML]]quot;

代码建\n

print(ordinal(32)) # 32nd

JavaScript

function ordinal(n) {  const mod100 = n % 100;  if (mod100 [[NEWS.CONTENT_HTML]]gt;= 11 [[NEWS.CONTENT_HTML]]amp;[[NEWS.CONTENT_HTML]]amp; mod100 [[NEWS.CONTENT_HTML]]lt;= 13) return `${n}th`;  const mod10 = n % 10;  return `${n}${({1:'st',2:'nd',3:'rd'}[mod10] || 'th')}`;

免再出\n

}console.log(ordinal(32)); // 32nd

律用否则\n

建议尽快替换海报或在配文中更正为 “32nd Anniversary/Birthday”。

甘肃省 南岗区 中山路176号

版权所有:重庆澳客 工程有限公司

京ICP备10004460号

渝公网安备 50023402000451号

18700001141