Files
bible/rules/patterns/web-visual-baseline/formatting/money.md
T

19 lines
778 B
Markdown
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Whole-unit amounts and missing values
This USD example follows the operator UI's display convention. Currency is a product choice, not a shared
hardcoded default. Do not use `value || ''`: a known zero must remain visible.
```js
function displayUSD(value) {
if (value === null || value === undefined || value === '') return '';
const amount = Number(value);
if (!Number.isFinite(amount)) return '';
const rounded = Math.round(amount);
return `${rounded < 0 ? '-' : ''}$${Math.abs(rounded).toLocaleString('ru-RU')}`;
}
```
`displayUSD(13320.4)` renders `$13 320`; `displayUSD(0)` renders `$0`.
Table cells use `text-align: right; font-variant-numeric: tabular-nums`.
For compact metrics, use a shared formatter rather than deriving an abbreviated value per page.