summaryrefslogtreecommitdiffstats
path: root/intl/icu_capi/js/package/test/fixed-decimal-format.mjs
blob: f49a0494cf06fcc9d65168eefe74683cef878250 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// This file is part of ICU4X. For terms of use, please see the file
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

import test from 'ava';

import { ICU4XFixedDecimal, ICU4XLocale, ICU4XDataProvider, ICU4XFixedDecimalFormatter } from "../index.js"

const locale = ICU4XLocale.create_from_string("bn");
const provider = ICU4XDataProvider.create_compiled();
const format = ICU4XFixedDecimalFormatter.create_with_grouping_strategy(provider, locale, "Auto");

test("format a simple decimal", t => {
  const decimal = ICU4XFixedDecimal.create_from_i32(1234);
  decimal.multiply_pow10(-2);

  t.is(format.format(decimal), "১২.৩৪");
});

test("format a long decimal", t => {
  const decimal = ICU4XFixedDecimal.create_from_i32(1000007);

  t.is(format.format(decimal), "১০,০০,০০৭");
});

test("format a negated, scaled decimal", t => {
  const decimal = ICU4XFixedDecimal.create_from_i32(1000007);
  decimal.multiply_pow10(2);
  decimal.set_sign("Negative");

  t.is(format.format(decimal), "-১০,০০,০০,৭০০");
});