Pass ToLocaleString() to infiniteHitsItem

Hello everyone.
I have a problem with my code. I use InstantSearch JS and infiniteHits widget.
My website displays prices of different products, all of them above 1 000€.
100000€ is quite unconfortable to read, 100 000€ is much better.
But I don’t know how to use toLocaleString() method in my JS.

How can I do that ?
My widget’s code is:

        container: '#infinitehits-container',
        showMoreLabel: "Plus de résultats",
        templates: {
            item: '<a class="link-item" href="{{{url_sous_modele}}}">' +
                    '<div class="img__container">' +
                        '<img class="infinitehits__img" src="{{{ img_url }}}">' +
                    '</div>' +
                    '<div class="left-hit__content">' +
                        '<div class="hit__marque">{{{ brand }}}</div>' +
                        '<div class="hit__sous_modele2">{{{ product }}}</div>' +
                        '<div class="hit__type">{{{ type }}}</div>' +
                        '<div class="hit__precision">{{{ precision }}}</div>' +
                        '<div class="hit__year_interval">{{{ year_interval }}}</div>' +
                    '</div>' +
                    '<div class="right-hit__content">' +
                        '<div class="price__actual">{{{ price }}}</div>' +
                    '</div>' +
                '</div>' +

I don’t know how to transform {{{ price }}} to suit my needs.

Hi @qbolgi

you can try injecting a template function instead of the template directly. Let me show you how:

instead of this

templates: {
    item: '<span>{{{ price }}}</span>'

do this:

templates: {
    item: function(item) {
       return '<span>' + item.price.toLocaleString() +  '</span>'

I hope this helps

It was item.price.toLocaleString() but thank you very much for your answer.

It helped me a lot !

you’re right, I’ve updated the example with your fix. Thank you