如何将分数舍入为3小数点? [英] How to round the fraction into 3 decimal point?

查看:89
本文介绍了如何将分数舍入为3小数点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算百分比。下面给出的查询正确显示百分比。但输出结果如34.3452344。我需要将分数减少到34.345。如何修改以下给定的查询。帮我找到合适的解决方案。谢谢。

Hi, I want to calculate percentage. The given below query showing the percentage properly. But the output is like 34.3452344. I need to reduce fraction as 34.345. How can I modify the given below query. help me to find a proper solution. Thank you.

SELECT SlNo, SiteID, OnTime, DueTime, (OnTime * 100.0) / NULLIF (Max(OnTime) OVER (), 0) Percentage1, (DueTime * 100.0) / NULLIF (Max(OnTime) OVER (), 0) Percentage2
FROM  tbl_Per

推荐答案

使用 ROUND - http://msdn.microsoft.com/en-us/library/ms175003.aspx [ ^ ]。
Use ROUND - http://msdn.microsoft.com/en-us/library/ms175003.aspx[^].


似乎您正在使用MS SQL SERVER

尝试 STR [ ^ ] function
Seems you are using MS SQL SERVER
try the STR[^] function


你可以尝试转换,像这:

You could try convert, something like this:
--data setup
declare @percent numeric(12,8);
set @percent = 34.3452344;
--query
select convert(decimal(12,3), @percent) percentage;
--result
--34.345


这篇关于如何将分数舍入为3小数点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆