Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • FORMAT(X,D[,locale]) function mysql

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 644
    Comment on it

    FORMAT(X,D[,locale])

    In mysql FORMAT function is used for formats a number X to a format like '#,###,###.##' and rounded to decimal places, and it returns the result as a string. If D is 0, the result has no decimal point. The third optional parameter is used for which local region you want in output, for example you want the result in US manner then you should need to use 'en_US' and if you want in indian english then 'en_IN' and same for all others. Here are some example-

    mysql> SELECT FORMAT(123456987.232,2);
    +-------------------------+
    | FORMAT(123456987.232,2) |
    +-------------------------+
    | 123,456,987.23          |
    +-------------------------+
    1 row in set (0.02 sec)
    
    mysql> SELECT FORMAT(123456987.237,2);
    +-------------------------+
    | FORMAT(123456987.237,2) |
    +-------------------------+
    | 123,456,987.24          |
    +-------------------------+
    1 row in set (0.00 sec)
    
    mysql> SELECT FORMAT(123456987.237,4);
    +-------------------------+
    | FORMAT(123456987.237,4) |
    +-------------------------+
    | 123,456,987.2370        |
    +-------------------------+
    1 row in set (0.00 sec)
    
    mysql> SELECT FORMAT(123456987.237,4,hi_IN);
    ERROR 1054 (42S22): Unknown column 'hi_IN' in 'field list'
    mysql> SELECT FORMAT(123456987.237,4,'hi_IN');
    +---------------------------------+
    | FORMAT(123456987.237,4,'hi_IN') |
    +---------------------------------+
    | 123,456,987.2370                |
    +---------------------------------+
    1 row in set (0.02 sec)
    
    mysql> SELECT FORMAT(123456987.237,0,'en_IN');
    +---------------------------------+
    | FORMAT(123456987.237,0,'en_IN') |
    +---------------------------------+
    | 12,34,56,987                    |
    +---------------------------------+
    1 row in set (0.00 sec)
    
    mysql> SELECT FORMAT(123456987.237,0,'en_US');
    +---------------------------------+
    | FORMAT(123456987.237,0,'en_US') |
    +---------------------------------+
    | 123,456,987                     |
    +---------------------------------+
    1 row in set (0.00 sec)
    
    mysql> SELECT FORMAT(123456987.237,2,'en_US');
    +---------------------------------+
    | FORMAT(123456987.237,2,'en_US') |
    +---------------------------------+
    | 123,456,987.24                  |
    +---------------------------------+
    1 row in set (0.00 sec)
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: