oracle function to_char(data,'FM999,999,999,999,990.00') format data (transfer)

Reprinted from: https://blog.csdn.net/fupengyao/article/details/52778565

Encountered the problem of oracle fetching format, here is a note

We usually want to make it display the format we need after doing data arithmetic. Here is a simple way

to_char(data,'FM999,999,999,999,990.00')

example:

select to_char(0.59/1.00*100,'FM999,999,999,999,990.00')||'%' from dual 

The result is: 59.00%

The following is a detailed introduction (copy)

select to_char(0.596,'FM999,999,999,990.00') from dual

  The result of its execution is as follows:

  How to find a decimal like 0.60 with 0, the answer is: use the above format

  ①The 9 stands for: if there is a number, it will display the number, if it does not exist, it will display a space

  ②Its 0 represents: if there is a number, it will display the number, and if it does not exist, it will display 0, that is, a placeholder.

  ③ Its FM representative: delete if the space is caused by 9, then delete it.

  The specific difference can be seen

Selec length(to_char(1.00,'999,999,999,999,999,999,999,990.00')), length(to_char(1.00,'FM999,999,999,999,999,999,999,990.00')) from dual

  the result is:

  ④ Rounding up: 0.596 becomes 0.60. I don’t know if you have noticed it. If you don't want to round, you need to trunc down, as follows:

  The result is 0.59

  ⑤ Solve the case of list 100,000,000

select to_char(10000000000,'FM999,999,999,990.00') from dual

  The above function works with fixed decimal point format. And if there is no decimal point?

  ⑥ Solve the situation of multiple points after the integer

select to_char(10000000000,'FM999,999,999,990.99') from dual

  Something like this would happen: 10,000,000,000.

  This type of solution needs to first determine whether the word data contains. (in the case of dots)

  If there is a bit, then instr()

  Otherwise directly to_cahr()

  This function is applicable to: the page does not display 0 (custom attributes of the class, there is no attribute b in class A, it is suitable for the case of assigning values ​​through sqlMap query, it is not necessary to use it under normal circumstances), the front and back list display does not display 0, 10,000,000,000 format for front and back lists.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324581626&siteId=291194637