mysql decimal and type conversion functions

 

two decimal places

  • SELECT ROUND( 123456789.3563898,2),TRUNCATE(123456789.3563898,2),FORMAT(123456789.3563898,2);

         

Type conversion functions convert() and cast()

CAST(value as type);
CONVERT(value, type);
The types that can be converted are limited. This type can be one of the following values:

Binary, with the effect of the binary prefix: BINARY
character type, with parameters: CHAR()
date: DATE
time: TIME
date and time type: DATETIME
floating point number: DECIMAL
integer: SIGNED
unsigned integer: UNSIGNED

  • SELECT convert (20180502185200,DATE),convert(20180502185200,TIME),convert(20180502185200,DATETIME)

        

  • SELECT cast(20180502185200 as DATE),cast(20180502185200 as TIME),cast(20180502185200 as DATETIME)

  • SELECT CONVERT(100.3465,DECIMAL(10,2)); 100.35

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325172961&siteId=291194637