Test case details

Preparation Code

const dataAsUnitsNanos = { units: BigInt(92), nanos: BigInt(99 * 1e6)} const dataAsUnitsNanosNums = { units: 92, nanos: 99 } const dataAsString = '92.99' const dataAsNumber = 92.99 const intlOptions = { style: "currency", currency: "USD" }; const numberFormat = new Intl.NumberFormat("en-US", intlOptions);

Test cases

Test #1

const dataAsNumberFormatted = numberFormat.format(dataAsNumber); console.log(dataAsNumberFormatted, 'number')

Test #2

const dataAsStringFormatted = numberFormat.format(parseFloat(dataAsString)); console.log(dataAsStringFormatted, 'string')

Test #3

const dataAsStringFormattedWithoutParsefloat = numberFormat.format(dataAsString); console.log(dataAsStringFormattedWithoutParsefloat, 'string no parsefloat')

Test #4

const dataAsUnitNanosNums = numberFormat.format(`${dataAsUnitsNanosNums.units}.${dataAsUnitsNanosNums.nanos}`); console.log(dataAsUnitNanosNums, 'units/nanos as nums')

Test #5

const dataAsUnitsNanosFormatted = numberFormat.format(Number(dataAsUnitsNanos.units) + (Number(dataAsUnitsNanos.nanos) / 1e6)); console.log(dataAsUnitsNanosFormatted, 'units/nanos')