欢迎光临雷速官网!
30年研发科技型企业专业生产新型、高效、节能、环保的单元设备
全国咨询热线:18800009387
联系我们
雷速
全国免费服务热线:18800009387
手机:
邮箱:
天津市 经济开发区 解放大道133号
联系人:苑 先生
您的位置: 首页 > 行业动态 > 详细内容
行业动态

print(ordinal(32)) # 32nd

时间:2016-12-16 来源:雷速

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

快速规则

  • 先看最后两位: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)
    • 错可以在\n

举例

  • 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

出图前用小\n

JavaScript

常见的英\n

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')}`;}console.log(ordinal(32)); // 32nd

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