File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed
Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change 1818* 2) Use RegExp to format string as required *
1919* *
2020***************************************************************************************/
21- function DivisionStringified(num1,num2) {
22-
23- var tot = Math.round(num1 / num2);
24- var newNum = tot.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
21+ function DivisionStringified(num1, num2) {
22+ // Perform the division and round the result to the nearest integer
23+ const result = Math.round(num1 / num2);
2524
26- return newNum;
27-
25+ // Convert the result to a string and format it with commas
26+ return result.toLocaleString();
2827}
28+
29+ // Test cases
30+ console.log(DivisionStringified(123456789, 10000)); // Expected output: "12,346"
31+ console.log(DivisionStringified(1000000, 3)); // Expected output: "333,333"
You can’t perform that action at this time.
0 commit comments