Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
How to update % printed to Console from MongoDB?
To update and print percentage values to console from MongoDB script, create a variable with your numeric value and use the print() method with toFixed() to format decimal places.
Syntax
var variableName = numericValue; print(variableName.toFixed(decimalPlaces) + " %");
Example
Create a variable with a percentage value and format it to 2 decimal places ?
var amount = 10.58945; print(amount.toFixed(2) + " %");
The output of the above code is ?
10.59 %
Key Points
- Use
toFixed()to control the number of decimal places displayed. - The
print()method outputs directly to the MongoDB shell console. - Concatenate the "%" symbol using the
+operator.
Conclusion
Use print() with toFixed() to display formatted percentage values in MongoDB shell. This method provides clean console output with controlled decimal precision.
Advertisements
