oracle 数字格式转换

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12777170/
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 01:09:20  来源:igfitidea点击:

Number format converting

oracleplsql

提问by Hyman

I have a currency amount value like this;

我有这样的货币金额值;

22200000

I want to convert this number to;

我想将此数字转换为;

22,2  (Number format)

How can I do this?

我怎样才能做到这一点?

回答by Ravindra Bagale

use to_char()function. Example

使用to_char()功能。例子

to_char(3510.78, ',999.00') 

would return

会回来

 ,510.78

回答by Hyman

I found the answer: SELECT TO_CHAR (22200000 / 1000000, '999,999,999,999.99') FROM dual

我找到了答案:SELECT TO_CHAR (22200000 / 1000000, '999,999,999,999.99') FROM dual

回答by Hyman

You can use Oracle Built-in function round().

您可以使用 Oracle 内置函数 round()。

The ROUND function accepts a number and returns another number rounded to the specified number of places to the right of the decimal point. If you do not specify that number, ROUND will return a number rounded to the nearest integer

ROUND 函数接受一个数字并返回另一个四舍五入到小数点右侧指定位数的数字。如果您不指定该数字,ROUND 将返回一个四舍五入到最接近的整数的数字

For instance:

例如:

    select 1/3, round(1/3, 2) from dual;

       1/3 ROUND(1/3,2)
---------- ------------
.333333333          .33

More info: Working with Numbers in PL/SQL

更多信息:在 PL/SQL 中使用数字