-
Notifications
You must be signed in to change notification settings - Fork 23.1k
Closed
Labels
Content:JSJavaScript docsJavaScript docseffort: mediumThis task is a medium effort.This task is a medium effort.help wantedIf you know something about this topic, we would love your help!If you know something about this topic, we would love your help!
Description
What information was incorrect, unhelpful, or incomplete?
The list of 'possible types' is incomplete, when using Intl.NumberFormat({notation: 'compact'}).formatToParts(number) the magnitude of the value is passed in as a part with type: 'compact'
Specific section or headline?
Description, under the Possible types are the following: list.
What did you expect to see?
`'compact' is missing in this list, as per EMCA 402, section 12.1.7 (PartitionNotationSubPattern), step 4. - c. - iv. - 2.:
iv. Else if p is equal to "compactSymbol", then
- [...]
- Append a new Record { [[Type]]: "compact", [[Value]]: compactSymbol } as the last element of result.
as well as step 4. - c. - v. - 2.:
v. Else if p is equal to "compactName", then
- [...]
- Append a new Record { [[Type]]: "compact", [[Value]]: compactName } as the last element of result.
Did you test this? If so, how?
JavaScript code using the part type:
const compactFormat = Intl.NumberFormat('en', {
notation: 'compact',
compactDisplay: 'short',
style: 'decimal',
maximumFractionDigits: 3,
});
// formatValue(42174812) => {formatted: '42.175', magnitude: 'M'}
function formatValue(value) {
let magnitude = '';
return {
formatted: compactFormat
.formatToParts(value)
.reduce((formatted, part) => {
switch (part.type) {
case 'compact':
magnitude = magnitude + part.value;
break;
default:
formatted = formatted + part.value;
}
return formatted;
}, ''),
magnitude: magnitude
};
}
console.log(formatValue(42174812));outputs
Object { formatted: "42.175", magnitude: "M" }
MDN Content page report details
- Folder:
en-us/web/javascript/reference/global_objects/intl/numberformat/formattoparts - MDN URL: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts
- GitHub URL: https://github.com/mdn/content/blob/master/files/en-us/web/javascript/reference/global_objects/intl/numberformat/formattoparts/index.html
- Report started: 2020-12-21T12:59:30.442Z
Metadata
Metadata
Assignees
Labels
Content:JSJavaScript docsJavaScript docseffort: mediumThis task is a medium effort.This task is a medium effort.help wantedIf you know something about this topic, we would love your help!If you know something about this topic, we would love your help!