Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format a number 123456 to 123,456 in mongodb

I am getting a number (e.g., 450000) as a result from a mongodb query. I want to format the number with a thousands separator (like currency) as 450,000.

Number: 1593324

Expected Output: 1,593,324

How can I achieve this in mongodb?

like image 807
Krunal Shah Avatar asked Sep 16 '25 01:09

Krunal Shah


1 Answers

you can't achieve this in mongodb because this is not programming language.

But You can use:

variableName.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");

and then call to store this string in database

example:

var test = 1593324;

test.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");

and then output i m getting : 1,593,324

like image 113
nitesh singh Avatar answered Sep 17 '25 19:09

nitesh singh