的小数位数的数量
使用mysql,我需要一些帮助从多个表创建视图并执行一些计算。
我的问题是方程式增加了我的价值的小数点小数,有没有办法继续前进并避免那些额外的小数点?这是我的SQL语句
CREATE ALGORITHM=UNDEFINED DEFINER=`Tosby`@`%` SQL SECURITY DEFINER VIEW `view_products` AS select `tbl_products`.`id` AS
`id`,`tbl_products`.`name` AS `name`,`tbl_products`.`descr` AS `descr`,`tbl_products`.`image` AS `image`,`tbl_categories`.`name` AS
`category`,((`tbl_products`.`cost` * (`tbl_tax`.`amount` / 100)) + `tbl_products`.`cost`) AS `cost`,
`tbl_restaurants`.`name` AS `restaurant` from (((`tbl_products` join `tbl_categories` on((`tbl_products`.`category` = `tbl_categories`.`id`)))
join `tbl_tax` on((`tbl_products`.`tax` = `tbl_tax`.`id`)))
join `tbl_restaurants` on((`tbl_products`.`owner` = `tbl_restaurants`.`id`))) ;
给出问题的线是这个
((`tbl_products`.`cost` * (`tbl_tax`.`amount` / 100)) + `tbl_products`.`cost`) AS `cost`,
如何删除在场地长度中添加的额外小数点?请注意,等式中使用的所有字段都具有整数,作为数据类型,长度为4个字符。
使用 round()
SELECT ROUND(135.37589567657, 2); it will return 135.38
所以在你的情况下
round (((`tbl_products`.`cost` * (`tbl_tax`.`amount` / 100)) + `tbl_products`.`cost`),n)
其中n =要拥有
使用 format()
参考链接
SELECT FORMAT(12324.2573, 3); //output 12324.257