decimal128
Version:
Partial implementation of IEEE 754 Decimal128 decimal floating-point numbers
29 lines (22 loc) • 1.06 kB
JavaScript
import { Decimal128 } from "../src/Decimal128.mjs";
function getStartsString(count, integer) {
const fractionDigits = integer ? 0 : 1;
const options = { minimumFractionDigits: fractionDigits, maximumFractionDigits: fractionDigits };
const nf = new Intl.NumberFormat("en-EN", options);
const pr = new Intl.PluralRules("en-EN", options);
const plurals = { one: "star", other: "stars" };
return nf.format(count) + " " + plurals[pr.select(count)];
}
function getStarsAverage(stars) {
const sum = stars.reduce((a, b) => a + b);
return { average: sum / stars.length, one: stars.length === 1 }
}
// const { average, one } = getStarsAverage([1, 0, 2]);
// console.log(getStartsString(average, one));
let a = new Decimal128("1.0");
let b = new Decimal128("1");
console.log(a.divide(b).toString({ preserveTrailingZeroes: true }));
console.log(b.divide(a).toString({ preserveTrailingZeroes: true }));
let c = new Decimal128("3.0");
let d = new Decimal128("4");
console.log(c.divide(d).toString({ preserveTrailingZeroes: true }));