v8/test/intl/regress-9408.js
Frank Tang 5bd5fd74b5 Fix unified number format
1. Move the reading of Notation before calling
   SetNumberFormatDigitOptions()
   ( sync after https://github.com/tc39/proposal-unified-intl-numberformat/pull/37)
2. Sync SetNumberFormatDigitOptions to the spec.
3. Consider the case that while RoundingType is "compact-rounding"
   do not set the precision.
4. correct the tests accordingly.
5. Fix the rounding of notation: "compact" and put regression cases
   into test/intl/regress-9408.js

Bug: v8:9408
Change-Id: I78d66601fe21b1a74a50047b2abe6a2838a58b8c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1681599
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62450}
2019-06-28 18:49:06 +00:00

29 lines
1.2 KiB
JavaScript

// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-intl-numberformat-unified
// Test precision of compact-rounding
let compact = {notation: "compact"};
assertEquals("1.2K", (1234).toLocaleString("en", compact));
assertEquals("12K", (12345).toLocaleString("en", compact));
assertEquals("123K", (123456).toLocaleString("en", compact));
assertEquals("1.2M", (1234567).toLocaleString("en", compact));
assertEquals("54K", (54321).toLocaleString("en", compact));
let compact_no_rounding = {notation: "compact", minimumFractionDigits: 0};
assertEquals("1.234K", (1234).toLocaleString("en", compact_no_rounding));
assertEquals("12.345K", (12345).toLocaleString("en", compact_no_rounding));
assertEquals("123.456K", (123456).toLocaleString("en", compact_no_rounding));
assertEquals("1.235M", (1234567).toLocaleString("en", compact_no_rounding));
assertEquals("54.321K", (54321).toLocaleString("en", compact_no_rounding));
let fmt = new Intl.NumberFormat("en", compact_no_rounding);
assertEquals("1", fmt.format(1));
assertEquals("1K", fmt.format(1000));
assertEquals("1.234K", fmt.format(1234));
assertEquals("1.25K", fmt.format(1250));