[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 … Read more

[Solved] Print numbers in columns c++

I want to print a string array containing numbers organized in columns. The array contains {“2″,”1″,”3″,”16″,”8″,”3″,”4″,”1″,”2”} I want to print them in this form 2 16 4 1 8 1 3 3 2 For the the given code of yours, you can do following changes to achieve the result. Find the array length using sizeof(arr)/sizeof(*arr);. … Read more

[Solved] transforming elements in array from numbers to string

Map over the array and assign each key value pair to a new object after converting it to a string. const array = [{abcd:1, cdef:7},{abcd:2, cdef:8}, {abcd:3, cdef:9}]; array.map(el => { const stringObj = {} Object.keys(el).forEach(key => { stringObj[key] = el[key].toString(); }) return stringObj; }) 1 solved transforming elements in array from numbers to string