当前位置:网站首页>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
边栏推荐
- Wireshark network packet capture
- Qt编写物联网管理平台38-多种数据库支持
- 1011 World Cup betting (20 points) (pat a)
- 实战模拟│JWT 登录认证
- [graduation season] green ant new fermented grains wine, red mud small stove. If it snows late, can you drink a cup?
- 上线首月,这家露营地游客好评率高达99.9%!他是怎么做到的?
- Dark horse programmer - software testing - stage 07 2-linux and database -09-24-linux command learning steps, wildcards, absolute paths, relative paths, common commands for files and directories, file
- 凌云出海记 | 文华在线&华为云:打造非洲智慧教学新方案
- 1005 spell it right (20 points) (pat a)
- Find the nth power of 2
猜你喜欢
Huawei Nova 10 series supports the application security detection function to build a strong mobile security firewall
Swagger suddenly went crazy
Abc229 summary (connected component count of the longest continuous character graph in the interval)
公司要上监控,Zabbix 和 Prometheus 怎么选?这么选准没错!
多表操作-外连接查询
什么叫内卷?
Pytoch learning (4)
Regular replacement [JS, regular expression]
Pointnet / pointnet++ point cloud data set processing and training
Chrome开发工具:VMxxx文件是什么鬼
随机推荐
需求开发思考
Cbcgpprogressdlgctrl progress bar used by BCG
SSRS筛选器的IN运算(即包含于)用法
Find the nth power of 2
Niuke Xiaobai month race 7 who is the divine Archer
【历史上的今天】7 月 4 日:第一本电子书问世;磁条卡的发明者出生;掌上电脑先驱诞生
B2B mall system development of electronic components: an example of enabling enterprises to build standardized purchase, sale and inventory processes
Kotlin condition control
Pointnext: review pointnet through improved model training and scaling strategies++
Pytoch learning (4)
1007 maximum subsequence sum (25 points) (PAT class a)
凌云出海记 | 沐融科技&华为云:打造非洲金融SaaS解决方案样板
凌云出海记 | 一零跃动&华为云:共助非洲普惠金融服务
CANN算子:利用迭代器高效实现Tensor数据切割分块处理
1005 spell it right (20 points) (pat a)
1008 elevator (20 points) (PAT class a)
Educational Codeforces Round 22 E. Army Creation
Multi table operation - external connection query
实战模拟│JWT 登录认证
Qt编写物联网管理平台38-多种数据库支持