让我们首先创建一个表-
mysql> create table DemoTable ( Value float );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values(12.4567); mysql> insert into DemoTable values(124.7884); mysql> insert into DemoTable values(45.64643);
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+---------+ | Value | +---------+ | 12.4567 | | 124.788 | | 45.6464 | +---------+ 3 rows in set (0.00 sec)
以下是查询以舍入浮动记录并将结果显示在新列中-
mysql> select Value,ROUND(Value,2) AS RoundValue from DemoTable;
这将产生以下输出-
+---------+------------+ | Value | RoundValue | +---------+------------+ | 12.4567 | 12.46 | | 124.788 | 124.79 | | 45.6464 | 45.65 | +---------+------------+ 3 rows in set (0.00 sec)