totn MariaDB Functions

MariaDB: FORMAT Function

This MariaDB tutorial explains how to use the MariaDB FORMAT function with syntax and examples.

Description

The MariaDB FORMAT function formats a number as a format of '#,###.##', rounding it to a certain number of decimal places and then it returns the result as a string.

Syntax

The syntax for the FORMAT function in MariaDB is:

FORMAT( number, decimal_places )

Parameters or Arguments

number
The number to format.
decimal_places
The number of decimal places to round the number.

Note

  • If decimal_places is 0, then the FORMAT function returns a string with no decimal places.

Applies To

The FORMAT function can be used in the following versions of MariaDB:

  • MariaDB 10

Example

Let's look at some MariaDB FORMAT function examples and explore how to use the FORMAT function in MariaDB.

For example:

SELECT FORMAT(1287.635, 2);
Result: '1,287.64'

SELECT FORMAT(1287.635, 1);
Result: '1,287.6'

SELECT FORMAT(1287.635, 0);
Result: '1,288'