I have a question about decimal numbers. I need to convert my numbers to decimal but I couldn't get what I exactly want.

What I want is:
First of all I searched in here and found some solutions to change my numbers :
function number_format(string,decimals=2,decimal=',',thousands='.',pre='R$ ',pos=' Reais'){
var numbers = string.toString().match(/\d+/g).join([]);
numbers = numbers.padStart(decimals+1, "0");
var splitNumbers = numbers.split("").reverse();
var mask = '';
splitNumbers.forEach(function(d,i){
if (i == decimals) { mask = decimal + mask; }
if (i>(decimals+1) && ((i-2)%(decimals+1))==0) { mask = thousands + mask; }
mask = d + mask;
});
return pre + mask + pos;
}
var element = document.getElementById("format");
var money= number_format("130000",2,',','.');
element.innerHTML = money;
This code above gave me 20.911,56 but it didn't give me 130,000. Instead it is 1,300,00.What should I do? Can't I have them on the same time?
Just use Intl.NumberFormat as follows:
const formatter = new Intl.NumberFormat('en');
console.log(formatter.format(130000)); // 130,000
console.log(formatter.format(20911.56)); // 20,911.56