Standard built-ins
Intl.NumberFormat.prototype.formatToParts()
Return typed display pieces (integer, decimal, fraction, currency and others) in presentation order.
Formal Syntax & Structure
javascript syntaxjavascript
formatter.formatToParts(value)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| value | Number | BigInt | String | Numeric 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);