当前位置:网站首页>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
边栏推荐
- Development and construction of DFI ecological NFT mobile mining system
- Niuke Xiaobai month race 7 F question
- Free soldier
- 1007 maximum subsequence sum (25 points) (PAT class a)
- Explicit random number
- 【毕业季】绿蚁新醅酒,红泥小火炉。晚来天欲雪,能饮一杯无?
- Utilisation de la barre de progression cbcggprogressdlgctrl utilisée par BCG
- C语言-入门-基础-语法-流程控制(七)
- 关于联邦学习和激励的相关概念(1)
- Euler function
猜你喜欢
New wizard effect used by BCG
[problem] Druid reports exception SQL injection violation, part always true condition not allow solution
JVM系列之对象的创建
记一次 .NET 某工控数据采集平台 线程数 爆高分析
复杂因子计算优化案例:深度不平衡、买卖压力指标、波动率计算
做社交媒体营销应该注意些什么?Shopline卖家的成功秘笈在这里!
B2B mall system development of electronic components: an example of enabling enterprises to build standardized purchase, sale and inventory processes
华为nova 10系列支持应用安全检测功能 筑牢手机安全防火墙
紫光展锐完成全球首个 5G R17 IoT NTN 卫星物联网上星实测
Swagger suddenly went crazy
随机推荐
做社交媒体营销应该注意些什么?Shopline卖家的成功秘笈在这里!
C server log module
What are the consequences of closing the read / write channel?
泰山OFFICE技术讲座:关于背景(底纹和高亮)的顺序问题
HDU 1372 & POJ 2243 Knight moves (breadth first search)
2022 version of stronger jsonpath compatibility and performance test (snack3, fastjson2, jayway.jsonpath)
Employment prospects of neural network Internet of things application technology [welcome to add]
凌云出海记 | 一零跃动&华为云:共助非洲普惠金融服务
Optimize if code with policy mode [policy mode]
[QNX Hypervisor 2.2用户手册]6.3.1 工厂页和控制页
kotlin 继承
1008 elevator (20 points) (PAT class a)
Chrome development tool: what the hell is vmxxx file
1007 maximum subsequence sum (25 points) (PAT class a)
YOLOv5s-ShuffleNetV2
Matrix flip (array simulation)
漫谈客户端存储技术之Cookie篇
Online data migration scheme encountered in the project 1 - general idea sorting and technical sorting
Niuke Xiaobai month race 7 who is the divine Archer
C# 使用StopWatch测量程序运行时间