For AI agents: the complete documentation index is available at /tc39-atlas/llms.txt, the full documentation bundle is available at /tc39-atlas/llms-full.txt, and this page is available as Markdown at /tc39-atlas/proposals/intl-numberformat-round-option.md.
  • 简体中文
  • Intl.NumberFormat round option S0

    中文标题:Intl.NumberFormat 舍入选项

    提案概览
    提案速览

    该提案为 Intl.NumberFormat 引入一个 round 选项,允许指定不同于默认的 "half-even" 的舍入函数,例如 Math.ceilMath.floorMath.trunc。提案引用了 Unicode 技术标准 #35 作为参考。

    Note

    以下 README 来自上游仓库,其中的阶段或状态标注可能滞后;当前信息以提案概览为准。

    NumberFormat 舍入选项

    第 0 阶段提案

    允许为 NumberFormat 选择不同于 "half-even" 的舍入函数。例如:向上取整、向下取整或截断。

    此选项在 Unicode 技术标准 #35 第 3 部分“数字”中有所体现,其中指出“实现可以允许指定舍入模式以确定如何对值进行舍入”。

    http://www.unicode.org/reports/tr35/tr35-numbers.html#Rounding

    用法

    let formatUsingHalfEvenRounding = new Intl.NumberFormat("en").format(Math.PI);
    // "3.142"
    
    let formatUsingFloorRounding = new Intl.NumberFormat("en", {round: Math.floor}).format(Math.PI);
    // "3.141"
    
    let formatCurrencyUsingCeilRounding = new Intl.NumberFormat("en", {
      style: "currency",
      currency: "USD",
      currencyDisplay: "symbol",
      round: Math.ceil
    }).format(9.991);
    // "$10.00"