940d11ecee
This is a reland of 40af6aeebf
Change from the rollbacked version
- removes the passed test fixed by this PR in test/test262/test262.status
TBR=jkummerow@chromium.org
Original change's description:
> [intl] Impl ECMA402 PR 471 rounding behavior
>
> Fix awkward rounding behavior
> Change Intl::SetNumberFormatDigitOptions to fix the awkward rounding
> behavior in NumberFormat when formatting a currency with
> "maximumFractionDigits" set to a value less than 2.
>
> Bug: v8:10844
> Change-Id: I2ff4afa9f747cd79cb9964fe4c77a0dd2b8977b5
> Refs: https://github.com/tc39/ecma402/pull/471
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2442191
> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> Commit-Queue: Frank Tang <ftang@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#70270}
Bug: v8:10844
Change-Id: Icfe7363f63d402abccc038e2b8bd78b38d0d9c49
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2444210
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70273}
67 lines
2.8 KiB
JavaScript
Executable File
67 lines
2.8 KiB
JavaScript
Executable File
// Copyright 2015 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.
|
|
|
|
// Make sure minimumFractionDigits and maximumFractionDigits are honored
|
|
|
|
var nf = new Intl.NumberFormat("en-us", { useGrouping: false, minimumFractionDigits: 4, maximumFractionDigits: 8});
|
|
|
|
assertEquals("12345.6789", nf.format(12345.6789));
|
|
assertEquals("12345.678912", nf.format(12345.678912));
|
|
assertEquals("12345.6700", nf.format(12345.67));
|
|
assertEquals("12345.67891234", nf.format(12345.6789123421));
|
|
|
|
nf = new Intl.NumberFormat("en-us", { useGrouping: false, minimumFractionDigits: 4, maximumFractionDigits: 8, style: 'percent'});
|
|
|
|
assertEquals("12345.6789%", nf.format(123.456789));
|
|
assertEquals("12345.678912%", nf.format(123.45678912));
|
|
assertEquals("12345.6700%", nf.format(123.4567));
|
|
assertEquals("12345.67891234%", nf.format(123.456789123421));
|
|
|
|
nf = new Intl.NumberFormat('en', {minimumFractionDigits: 4, maximumFractionDigits: 8, style: 'currency', currency: 'USD'});
|
|
|
|
assertEquals("$54,306.404797", nf.format(54306.4047970));
|
|
assertEquals("$54,306.4000", nf.format(54306.4));
|
|
assertEquals("$54,306.40000001", nf.format(54306.400000011));
|
|
|
|
// Ensure that appropriate defaults exist when minimum and maximum are not specified
|
|
|
|
nf = new Intl.NumberFormat("en-us", { useGrouping: false });
|
|
|
|
assertEquals("12345.679", nf.format(12345.6789));
|
|
assertEquals("12345.679", nf.format(12345.678912));
|
|
assertEquals("12345.67", nf.format(12345.6700));
|
|
assertEquals("12345", nf.format(12345));
|
|
assertEquals("12345.679", nf.format(12345.6789123421));
|
|
|
|
nf = new Intl.NumberFormat("en-us", { useGrouping: false, style: 'percent'});
|
|
|
|
assertEquals("12346%", nf.format(123.456789));
|
|
assertEquals("12346%", nf.format(123.45678912));
|
|
assertEquals("12346%", nf.format(123.456700));
|
|
assertEquals("12346%", nf.format(123.456789123421));
|
|
assertEquals("12345%", nf.format(123.45));
|
|
|
|
// For currency, the minimum or the maximum can be overwritten individually
|
|
|
|
nf = new Intl.NumberFormat('en', {minimumFractionDigits: 0, style: 'currency', currency: 'USD'});
|
|
|
|
assertEquals("$54,306.4", nf.format(54306.4047970));
|
|
assertEquals("$54,306.4", nf.format(54306.4));
|
|
assertEquals("$54,306", nf.format(54306));
|
|
|
|
nf = new Intl.NumberFormat('en', {maximumFractionDigits: 3, style: 'currency', currency: 'USD'});
|
|
|
|
assertEquals("$54,306.405", nf.format(54306.4047970));
|
|
assertEquals("$54,306.40", nf.format(54306.4));
|
|
assertEquals("$54,306.00", nf.format(54306));
|
|
|
|
nf = new Intl.NumberFormat('en', {maximumFractionDigits: 0, style: 'currency', currency: 'USD'});
|
|
|
|
assertEquals("$54,306", nf.format(54306.4047970));
|
|
assertEquals("$54,306", nf.format(54306.4));
|
|
assertEquals("$54,306", nf.format(54306));
|
|
|
|
assertThrows(() => new Intl.NumberFormat('en',
|
|
{minimumFractionDigits: 1, maximumFractionDigits: 0, style: 'currency', currency: 'USD'}));
|