如何让 Oracle SQL 中的百分比显示小数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20361114/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 02:06:54  来源:igfitidea点击:

How to have a percentage in Oracle SQL show decimals?

sqloracledecimalpercentage

提问by Spartacus38

I have a query that shows how close a inventory count is to being complete. I would like it to show 2 numbers after the decimal, unless that number is 100 or 0. This is what I'm currently using and it outputs numbers like : 95, 100. I would like them to show 95.14, and 100(without decimal)

我有一个查询,显示库存盘点完成的程度。我希望它在小数点后显示 2 个数字,除非该数字是 100 或 0。这是我目前使用的,它输出的数字如:95、100。我希望它们显示 95.14 和 100(没有十进制)

NVL(ROUND(count(icqa_process_locations.icqa_count_attempt_id)/count(icqa_processes.icqa_process_id)*100,0),0)||'%' as "Percentage Complete"

NVL(ROUND(count(icqa_process_locations.icqa_count_attempt_id)/count(icqa_processes.icqa_process_id)*100,0),0)||'%' as "Percentage Complete"

回答by bigdavy

You actually didn't need add TO_CHAR, you just needed to change *100,0 to *100,2 to tell it how many decimal places you wanted:

您实际上不需要添加 TO_CHAR,您只需要将 *100,0 更改为 *100,2 即可告诉它您想要的小数位数:

NVL(ROUND(count(icqa_process_locations.icqa_count_attempt_id)/count
      (icqa_processes.icqa_process_id)*100,2),0)||'%' as "Percentage Complete"

回答by Spartacus38

I have answered my own question. Sorry I'm a newbie! But here is my fix in case anyone has something similar.

我已经回答了我自己的问题。抱歉我是新手!但这是我的解决方法,以防万一有人有类似的情况。

I added to_char to the front, and changed *100,0 to *100,2.

我在前面加了 to_char,把 *100,0 改为 *100,2。

to_char(NVL(ROUND(count(icqa_process_locations.icqa_count_attempt_id)/count
    (icqa_processes.icqa_process_id)*100,2),0))||'%' as "Percentage Complete"