Preparation Code Preparation HTML (this will be inserted in the <body>
of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries)
Setup JS 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);
Teardown JS
Test cases
Test #1 Title *
Async
Code * const dataAsNumberFormatted = numberFormat.format (dataAsNumber);
console .log (dataAsNumberFormatted, 'number' )
Test #2 Title *
Async
Code * const dataAsStringFormatted = numberFormat.format (parseFloat (dataAsString));
console .log (dataAsStringFormatted, 'string' )
Title *
Async
Code * const dataAsStringFormattedWithoutParsefloat = numberFormat.format (dataAsString);
console .log (dataAsStringFormattedWithoutParsefloat, 'string no parsefloat' )
Title *
Async
Code * const dataAsUnitNanosNums = numberFormat.format (`${dataAsUnitsNanosNums.units} .${dataAsUnitsNanosNums.nanos} ` );
console .log (dataAsUnitNanosNums, 'units/nanos as nums' )
Title *
Async
Code * const dataAsUnitsNanosFormatted = numberFormat.format (Number (dataAsUnitsNanos.units ) + (Number (dataAsUnitsNanos.nanos ) / 1e6 ));
console .log (dataAsUnitsNanosFormatted, 'units/nanos' )