Oracle removes 0 at the end of a decimal number

Source: Internet
Author: User
Tags rtrim
Sometimes, when you use an OraclePLSQL query statement to convert a field of the number type to a field of the varchar2 type, it often appears on reports or pages:

Oracle PL/SQL query statements sometimes convert the number type field to the varchar2 type field, which often appears on reports or pages:

Oracle PL/SQL query statements sometimes convert the number type field to the varchar2 type
Reports or pages are frequently displayed:

. 440
. 441
1.0
10.100

And so on, or the 0 before the decimal point is removed by the to_char or cast function, or the 0 at the end of the invalid decimal point is not removed.
The jsp interface is easy to handle. You can use a method similar to the following:

Jsp code

  • Weight: (Km)
    However, in a super report, the numbers to be displayed in cells are not very easy to process. You need to process the queried fields,
    The following describes the solution:
    Step 1: Save the 0 before the decimal point and remove the 0 at the end of the decimal point, and remove the redundant spaces generated by formatting:

    Plsql code

    Select t. num from (select ltrim (rtrim (to_char (0.44, '2017. 000 '), '0'), '') as num from dual unionselect ltrim (rtrim (to_char (0.441, '100. 000 '), '0'), '') as num from dual unionselect ltrim (rtrim (to_char (1.0, '100. 0 '), '0'), '') as num from dual unionselect ltrim (rtrim (to_char (10.100, '100. 000 '), '0'), '') as num from dual) t/* result: 0.2.16.4411.10.1 */

    Step 2: Remove unnecessary decimal points:

    Plsql code

    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.