test262/test/intl402/11.3.2_FN_3_b.js

29 lines
1.0 KiB
JavaScript
Raw Normal View History

2012-04-16 22:23:13 +02:00
// Copyright 2012 Google Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
2014-07-25 00:41:42 +02:00
es5id: 11.3.2_FN_3_b
description: >
Tests that Intl.NumberFormat.prototype.format formats percent
values properly.
2014-07-25 00:41:42 +02:00
author: Roozbeh Pournader
---*/
2012-04-16 22:23:13 +02:00
var numberFormatter = new Intl.NumberFormat();
var percentFormatter = new Intl.NumberFormat(undefined, {style: 'percent'});
2012-04-16 22:23:13 +02:00
var formattedTwenty = numberFormatter.format(20);
var formattedTwentyPercent = percentFormatter.format(0.20);
2012-04-16 22:23:13 +02:00
// FIXME: May not work for some theoretical locales where percents and
// normal numbers are formatted using different numbering systems.
if (formattedTwentyPercent.indexOf(formattedTwenty) === -1) {
2012-04-16 22:23:13 +02:00
$ERROR("Intl.NumberFormat's formatting of 20% does not include a " +
"formatting of 20 as a substring.");
}
2012-04-16 22:23:13 +02:00
// FIXME: Move this to somewhere appropriate
if (percentFormatter.format(0.011) === percentFormatter.format(0.02)) {
2012-04-16 22:23:13 +02:00
$ERROR('Intl.NumberFormat is formatting 1.1% and 2% the same way.');
}