How to format and display International prices in CMS Listings

@steven.riot - I see you were able to target your element with vanilla JS. Good.

Here is some code I cranked out for you that does a better job and is more flexible since it formats the number as either currency or decimal with support for any language when modified. Requires jQuery (because it is already loaded in wf). All anyone would need to do to reuse it is changed the selector $(".prixthumb") to match where it exists on their page or site. Then supply the correct parameters in the Intl.NumberFormat() function.

<script>
    $(document).ready(function () {
        
            $(".prixthumb").each(function () { 
                //this is the target text string converted to a number
                var numprice = Number($(this).text());
                // create a function to set the International number format  
                var nprice = Intl.NumberFormat(`en-US`, {
                        style : 'currency',
                        currency: 'EUR',
                        currencyDisplay: `symbol`,
                        minimumFractionDigits: 0
                        //maximumFractionDigits: 0
                    }
                );
            // replace the current value for  the new formatted value      
            $(this).text(nprice.format(numprice));
            })
        });
</script>

Here is a reference to the function

4 Likes