summaryrefslogtreecommitdiffstats
path: root/intl/icu_capi/js/package/test/fixed-decimal.mjs
blob: 1295d47c0e05a1acff9f2f10a0c95f4d5824547f (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
// 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 } from "../lib/index.js"

test("convert a simple decimal to a string", t => {
  const decimal = ICU4XFixedDecimal.create_from_i64(1234n);

  t.is(decimal.to_string(), "1234");
});

test("multiply a decimal by a power of 10", t => {
  const decimal = ICU4XFixedDecimal.create_from_i32(1234);
  decimal.multiply_pow10(-2);

  t.is(decimal.to_string(), "12.34");
});

test("negate a decimal", t => {
  const decimal = ICU4XFixedDecimal.create_from_i32(1234);
  decimal.set_sign("Negative");

  t.is(decimal.to_string(), "-1234");
});