背景

实际日常开发工作中,时时需要按指定格式保留小数位,但有时极易出错,现将使用round函数时的细微差异总结如下:

select  4/3 as c1
		,(4/3)::numeric as c2
		,round(4/3) as c3
		,round(4/3,4) as c4
		,round((4/3)::numeric,4) as c5
		,4::numeric/3::numeric as d1
		,round(4::numeric/3::numeric) as d3
		,round(4::numeric/3::numeric,4) as d4
结果

跑出来的结果
可仔细观察代码细微不同所带来的结果不同,在实际开发工作中根据自己需要合理使用round()函数

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐