Skip to content

Commit 2972e34

Browse files
authored
Update Division Stringified
1 parent da731ce commit 2972e34

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

Division Stringified

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@
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"

0 commit comments

Comments
 (0)