mirror of
https://github.com/nodejs/node.git
synced 2025-05-17 06:08:35 +00:00

PR-URL: https://github.com/nodejs/node/pull/42657 Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
31 lines
1.2 KiB
JavaScript
31 lines
1.2 KiB
JavaScript
// Copyright 2022 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-number-format-v3
|
|
|
|
// Check the rounding behavior.
|
|
// Based on https://tc39.es/proposal-intl-numberformat-v3/out/numberformat/diff.html#table-intl-rounding-modes
|
|
let inputs = [-1.5, 0.4, 0.5, 0.6, 1.5];
|
|
let expectations = {
|
|
"ceil": ["-1", "1", "1", "1", "2"],
|
|
"floor": ["-2", "0", "0", "0", "1"],
|
|
"expand": ["-2", "1", "1", "1", "2"],
|
|
"trunc": ["-1", "0", "0", "0", "1"],
|
|
"halfCeil": ["-1", "0", "1", "1", "2"],
|
|
"halfFloor": ["-2", "0", "0", "1", "1"],
|
|
"halfExpand": ["-2", "0", "1", "1", "2"],
|
|
"halfTrunc": ["-1", "0", "0", "1", "1"],
|
|
"halfEven": ["-2", "0", "0", "1", "2"],
|
|
};
|
|
Object.keys(expectations).forEach(function(roundingMode) {
|
|
let exp = expectations[roundingMode];
|
|
let idx = 0;
|
|
let nf = new Intl.NumberFormat("en", {roundingMode, maximumFractionDigits: 0});
|
|
assertEquals(roundingMode, nf.resolvedOptions().roundingMode);
|
|
inputs.forEach(function(input) {
|
|
let msg = "input: " + input + " with roundingMode: " + roundingMode;
|
|
assertEquals(exp[idx++], nf.format(input), msg);
|
|
})
|
|
});
|