Standard built-ins

Intl.NumberFormat.prototype.formatToParts()

Try the free JavaScript compiler

Return typed display pieces (integer, decimal, fraction, currency and others) in presentation order.

Formal Syntax & Structure

javascript syntaxjavascript
formatter.formatToParts(value)

Parameters & Attributes

NameTypeDescription
valueNumber | BigInt | StringNumeric value interpreted according to formatter.

Return Value

Array

Ordered objects with type and value.

Working Example

Example Snippetjavascript
const f=new Intl.NumberFormat("en-US",{minimumFractionDigits:2});console.log(f.formatToParts(3).find(p=>p.type==="fraction").value);
JavaScript Reference