Oracle的关于小数的使用

时间:2022-10-03 04:39:45

整理了部分Oracle的关于小数的使用方法,如下

--round(x,[y]) 舍入到小数点右边y位的x值
select round(1.23456,3) from dual; --1.235
select round(12345.6) from dual; -- --trunc(x,[y])返回截尾到y位小数的x值
select trunc(1.23456,3) from dual; --1.234
select trunc(12345.6) from dual; -- --格式化 to_char
select to_char(1234.56, '9999.9') from dual; -- 1234.6
select to_char(1234.56, '9,999.99') from dual; -- 1,234.56
select to_char(1234.56, '$9,999.00') from dual; -- $1,234.56
select to_char(21, '') from dual; -- --截取小数部分
select substr('12345.67890',instr('12345.67890','.')+1) from dual; -- --小数部分长度
select length(substr('12345.67890',instr('12345.67890','.')+1)) from dual; --