How to format numbers in mysql?

Member

by kadin , in category: MySQL , 9 months ago

How to format numbers in mysql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by lizzie , 9 months ago

@kadin 

In MySQL, you can format numbers using the FORMAT() function. This function takes two arguments: the number you want to format, and the number of decimal places you want to display.


Here's an example usage of the FORMAT() function in a query:

1
SELECT FORMAT(1234567.89, 2);


This query will format the number 1234567.89 to include 2 decimal places, resulting in the output 1,234,567.89.


You can also use the FORMAT() function to add commas as thousand separators. For example:

1
SELECT FORMAT(1234567.89, 0);


This query will format the number 1234567.89 to include 0 decimal places and commas as thousand separators, resulting in the output 1,234,568.


You can customize the formatting of numbers further by adjusting the arguments passed to the FORMAT() function.