[Solved] How do I apply currency or decimal formatting to all the numbers in a string without knowing their specific position in the string beforehand?


If the values over hundred should divided by 100 then this is the answer.

var str = "the bouncy 7000 bunny hops 4 you";
console.clear();
var result = str
  .replace(/\d+/g, num => {
    num = parseInt(num);
    return (num > 100 ? num / 100 : num) + ".00";
  });
console.log(result);

1

solved How do I apply currency or decimal formatting to all the numbers in a string without knowing their specific position in the string beforehand?