Use a report script to dynamically display decimal places

Source: Internet
Author: User
ArticleDirectory
    • Requirement Overview
    • Implementation

Requirement Overview

In some statistical reports, the value range of a certain number is quite large. In order to reduce the total number of digits displayed for a large data, a small data must be displayed with sufficient precision, that is to say, different decimal places are displayed based on the data size, which is similar to the floating point mechanism that represents the decimal data in the computer.

You can set the "format" attribute of data to display numbers in the specified format in a report. However, the preceding requirements cannot be achieved directly by setting the format, instead, we need to use the report Script Function.

Implementation

First, set the data format to the maximum number of decimal places required by the output. For example, if the format is "#, #0.000000", the data is always displayed with 5 decimal places. Then, use the report script to determine the decimal places to be output based on the data value size, and cut off the remaining decimal places to obtain the expected explicit text.

To write a report script on the "get show text script" attribute in the field or statistical box, you can set its display text. example scriptCode:

// Determine the number of digits to be displayed based on the Value
VaR v = sender. value;
VaR digit = 0;
If (V> 2000)
Digit = 0;
Else if (v> 1500)
Digit = 2;
Else if (v> 800)
Digit = 3;
Else
Digit = 5;

VaR text = sender. displaytext; // obtain the plain text generated based on the formatted string, for example, 123.45600
VaR Index = text. indexof ("."); // you can specify the decimal point.
If (digit> 0)
Index = index + digit + 1;
Else
Index = index;
Sender. displaytext = text. substr (0, index); // intercept the displayed text and set it to the displayed Text of the data.

Sample download (http://www.rubylong.cn/download/samples/FloatDecimal.grf)

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.