Components for formatting text

    With Component

    Without Component

    1. const showSymbol = options.showSymbol !== false;
    2. const showDecimals = options.showDecimals !== false;
    3. return num.toLocaleString('en', {
    4. style: showSymbol ? 'currency' : undefined,
    5. maximumFractionDigits: showDecimals ? 2 : 0
    6. }
    7. const Page = () => {
    8. const lambPrice = 1234.567;
    9. const jetPrice = 999999.99;
    10. const bootPrice = 34.567;
    11. <div>
    12. <p>One lamb is <span className="expensive">{numberToPrice(lambPrice)}</span></p>
    13. <p>One jet is {numberToPrice(jetPrice, { showDecimals: false })}</p>
    14. <p>Those gumboots will set ya back
    15. {numberToPrice(bootPrice, { showDecimals: false, showSymbol: false })}
    16. bucks.</p>
    17. </div>
    18. };