import { storiesOf, html } from '@open-wc/demoing-storybook'; import { css } from '@lion/core'; import { formatNumber, formatNumberToParts } from '../index.js'; const formatNumberDemoStyle = css` .demo-table { border-collapse: collapse; text-align: right; } .demo-table thead > tr { border-bottom: 1px solid grey; } .demo-table thead > tr > :first-child, .demo-table tbody > tr > :first-child, .demo-table tfoot > tr > :first-child { text-align: left; } .demo-table th, .demo-table td { padding: 8px; } `; const value = 1234.56; storiesOf('Localize System|Number', module) .add( 'formatNumber', () => html`
Formatted value is ${value}
| Options | Code | Output |
|---|---|---|
| Default | ${formatNumber(value)} | |
| Currency symbol |
formatNumber({ style: 'currency', currencyDisplay: 'symbol', currency: 'EUR'
})
|
${formatNumber(value, { style: 'currency', currencyDisplay: 'symbol', currency: 'EUR', })} |
| Currency code |
formatNumber({ style: 'currency', currencyDisplay: 'code', currency: 'EUR' })
|
${formatNumber(value, { style: 'currency', currencyDisplay: 'code', currency: 'EUR', })} |
| Locale | formatNumber({ locale: 'nl-NL' }) |
${formatNumber(value, { locale: 'nl-NL' })} |
| No decimals |
formatNumber({ minimumFractionDigits: 0, maximumFractionDigits: 0, })
|
${formatNumber(value, { minimumFractionDigits: 0, maximumFractionDigits: 0, })} |
Formatted value is ${value}
| Part | Output |
|---|---|
| ${part.type} | ${part.value} |
Formatted value is ${value}
| Locale | Output Euro | Output US Dollar |
|---|---|---|
| ${locale} | ${formatNumber(value, { locale, style: 'currency', currency: 'EUR' })} | ${formatNumber(value, { locale, style: 'currency', currency: 'USD' })} |