Decimal conversion of String Conversion functions in Oracle

Source: Internet
Author: User
Tags integer numbers

In Oracle, The String Conversion format of the to_char () function is summarized as follows: to_char (var [, format]) Function Conversion format description: 1. [format] '000000' N indicates the number of numbers in the converted format.
If the number of digits var is smaller than or equal to the number of digits in the conversion format 9, the character before the converted string is null; if the number of digits var is greater than the number of digits in the conversion format of 9, the conversion fails. After conversion, the number is displayed as N + 1 #. For decimal places, only the integer part is converted. 2. [format] '099' N is the number of numbers in the conversion format 9 and 0. If the number var is smaller than or equal to the number of numbers in the conversion format 9 + 0, the first empty character and (N-var digits-1) digits of the converted string are 0. If the number of var digits is greater than the number of 9 + 0 digits in the conversion format, the conversion fails, after conversion, the number is N + 1 #. For decimal places, only the integer part is converted. 3. The [format] '123' conversion rule is the same as (1) for decimal places, only the integer part is converted. 4. [format] '2017. 99 'n1 is the number of digits in the integer part format 9, N2 is the number of digits in the fractional part, and the number of digits in the var integer part conversion rule is the same as (1 ); if the number var is less than N2 in the fractional part, add 0 to the fractional part to add the number of N2. If the number of digits in the fractional part is greater than N2, extract 5 digits of N2 according to rounding. [format] '2017. 999 'conversion rules are roughly the same as (4). The difference is that (5) the processing of decimal places whose integer part is 0 is more perfect if: to_char (0.75, '123. 99 ') =. 75 to_char (0.75, '192. 990. 99 ') = 0.75 6. [format] The conversion rule of 'fm999' is the same as that of (1), but this format can delete spaces in front of the converted string. It can be said that the processing is improved. 7. [format] 'fm990. in the combination of 999 'format (5) and format (6), 0 is not automatically added to the fractional part, because 'fm' will process the 0 at the end of the decimal part as a short character and delete 8. [format] 'fm990. 990 'conversion rules are roughly the same as (7). The difference is that in (8) format, when the number of digits in the var decimal part is smaller than the decimal part in the conversion format, add 0 [format] '20180101' to the end. 900 'and [format]' 990. 990 'same 9. [format] 'fm990. 099' or 'fm990. the 100' two formats are the same. Processing the most perfect format for decimal numbers can convert the numbers into strings as they are. Of course, the digits in the integer part cannot be less than the digits in the integer part of the number var 10. [format] to_char (var) is the most perfect format for Processing Integer numbers. Of course, to_char (var, 'fm99999999999999 ') can also be used, but this method is a bit redundant, in addition, the number of 9 in the conversion format must be greater than the number of bits in var to be successfully converted. Otherwise, the conversion cannot be successful.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.