F
F
First Name2017-12-15 18:31:45
JavaScript
First Name, 2017-12-15 18:31:45

How to format number in js and output in pug?

Good day to all.
I pass in the object
offers
{
"id":129,
"logourl":"129.png",
"mincreditsum":7000,
"maxcreditsum":200000"
}
I want to format mincreditsum and maxcreditsum and bring them to the form 7,000 and 200,000.
I found such a regular expression. Now I output it in a loop like this
replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ')

each offer,index in offers_arr
        span.minsumm !{offer.mincreditsum}
        span.maxsumm !{offer.maxcreditsum}

How can you use it regularly?
Now declared a function
script.
    var myFunc = function (a) {
        return a.replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
    }

And I call it in a loop
each offer,index in offers_arr
     span#summin!= myFunc(offer.mincreditsum)

But it throws an error
Call to undefined function myFunc()

How will it be right?
Thanks in advance for your replies.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question