目录

MySQL FORMAT() 函数

示例

将数字格式设置为"#,###,###.##"(并四舍五入到小数点后两位):

SELECT FORMAT(250500.5634, 2);
亲自试一试 »

定义和用法

FORMAT() 函数将数字格式化为 "#,###,###.##" 等格式,四舍五入到指定的小数位数,然后以字符串形式返回结果。

语法

FORMAT( number, decimal_places)

参数值

Parameter Description
number Required. The number to be formatted
decimal_places Required. The number of decimal places for number. If this parameter is 0, this function returns a string with no decimal places

技术细节

工作于: 从 MySQL 4.0 开始

更多示例

示例

将数字格式化为 "#,###,###.##" 格式(并舍入小数点后 0 位):

SELECT FORMAT(250500.5634, 0);
亲自试一试 »