当前位置:网站首页>Oracle database, numbers Force 2 decimal places to display-Alibaba Cloud
Oracle database, numbers Force 2 decimal places to display-Alibaba Cloud
2022-07-04 20:17:00 【wx61ea6d592e17b】
In the banking, financial and other sensitive to the digital requirements of the system, the digital display generally have strict requirements.
This is a requirement, title, which requires numbers to be displayed in two decimal places, and if there are no decimals, force the display to 0.
For example:
123.4 Display as 123.40
12 Display as 12.00
0 Display as 0.00
I thought this was a relatively simple question, and Oracle itself provided the TO_CHAR function, with the Format function, to satisfy the condition:
[SQL]
- Select To_char (123.4, ' 9999990.00 ') as AA from dual;
- Select To_char (n, ' 9999990.00 ') as AA from dual;
- Select To_char (0, ' 9999990.00 ') as AA from dual;
- Select To_char (123.4, ' fm9999990.00 ') as AA from dual;
- Select To_char (n, ' fm9999990.00 ') as AA from dual;
- Select To_char (0, ' fm9999990.00 ') as AA from dual;
At this point, I thought the problem was solved, but did not notice that the above statement is formatted with a string, not a number!!
requirements, very clear requirements, the number is formatted, the results are still numbers.
Analysis: This requirement is a very common and normal requirement, and since Oracle is so powerful, it should provide relevant methods,
So, to find the relevant documentation for Oracle, finally, find a cast function, which is responsible for the type conversion, try it.
The results show that the method is feasible. Test the SQL statement as follows:
[SQL]
- Select CAST (1234.4 as number (2)) as AA from dual;
- Select CAST ( as number (2)) as AA from dual;
- Select CAST (0 as number (2)) as AA from dual;
PS: Append a point, the string can be directly type conversion, without using the To_number () function to do intermediate conversion. The SQL statements are as follows:
[SQL]
- select cast ( ' 1234.4 ' as number (10, 2) ) as aa from dual ;
- select cast ( ' 12 ' as number (10, 2) ) as aa from dual ;
- Li class= "alt" > select cast ( ' 0 ' as number (10, 2) ) as aa from dual ;
PS: Add 2nd, online to see if it is said that after the decimal point is full, PL/SQL version is concerned.
I did not do the verification, do not express personal opinion, only in this record, such as later encountered problems, and then verify
Oracle database, numbers Force 2 decimal places to display
Related Article: how to round numbers to 2 decimal places
边栏推荐
- What is the application technology of neural network and Internet of things
- 被奉为经典的「金字塔原理」,教给我们哪些PPT写作技巧?
- abc229 总结(区间最长连续字符 图的联通分量计数)
- kotlin 循环控制
- 更强的 JsonPath 兼容性及性能测试之2022版(Snack3,Fastjson2,jayway.jsonpath)
- 如何让你的小游戏适配不同尺寸的手机屏幕
- In the first month of its launch, the tourist praise rate of this campsite was as high as 99.9%! How did he do it?
- Employment prospects and current situation of Internet of things application technology
- Optimize if code with policy mode [policy mode]
- Explicit random number
猜你喜欢
ACM组合计数入门
【历史上的今天】7 月 4 日:第一本电子书问世;磁条卡的发明者出生;掌上电脑先驱诞生
什么叫内卷?
Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines
Free soldier
The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!
Pythagorean number law (any three numbers can meet the conditions of Pythagorean theorem)
Actual combat simulation │ JWT login authentication
黑马程序员-软件测试--08阶段2-linux和数据库-23-30-进程端口相关,修改文件权限,端口号信息的获取,程序和进程相关操作,linux命令案例
Pytoch learning (4)
随机推荐
Siemens HMI download prompts lack of panel image solution
凌云出海记 | 文华在线&华为云:打造非洲智慧教学新方案
On communication bus arbitration mechanism and network flow control from the perspective of real-time application
原来这才是 BGP 协议
1011 World Cup betting (20 points) (pat a)
SSRS筛选器的IN运算(即包含于)用法
BCG 使用之CBCGPProgressDlg进度条使用
上线首月,这家露营地游客好评率高达99.9%!他是怎么做到的?
双冒号作用运算符以及命名空间详解
什么叫内卷?
Utilisation de la barre de progression cbcggprogressdlgctrl utilisée par BCG
泰山OFFICE技术讲座:关于背景(底纹和高亮)的顺序问题
BCG 使用之CBCGPProgressDlgCtrl進度條使用
1006 sign in and sign out (25 points) (PAT class a)
Process of manually encrypt the mass-producing firmware and programming ESP devices
Educational Codeforces Round 22 E. Army Creation
Decryption function calculates "task state and lifecycle management" of asynchronous task capability
CANN算子:利用迭代器高效实现Tensor数据切割分块处理
Actual combat simulation │ JWT login authentication
Template_ Judging prime_ Square root / six prime method