VBScript Bug? (turn)

xiaoxiao2021-03-06  86

VBScript Bug?

Web development /ASP.net

Round function

Returns the value of the number of points to the number of points.

Round (Expression [, NumDecimalPlace])

parameter

EXPRESSION

required. Numerical expressions were rounded out.

NumDecimalPlace

Optional. The figures indicate how many counts in the right side of the decimal point are rounded. If omitted, the ROUND function returns an integer.

Description

The following example uses the Round function to bring the value round to two decimals:

Dim myvar, pi

Pi = 3.14159

MYVAR = ROUND (PI, 2) 'Myvar Contains 3.14.

However, Round (1.25, 1) returned to 1.2, not 1.3 ...

Cause: The PC uses "four hits into five-way pairs" instead of "rounding".

(FootballBoy) is provided by this)

His reason I also posted:

Reply to: footballboy (Zheng Chuangbin) 2002-5-30 11:48:13

I used to find this problem before I explore some. The result is as follows:

I understand this way, if you need to be rounded, "less than 5" or "greater than 5" is required, according to the usual four-bedroom processing. If "If you need to be rounded, you need to be rounded" accurate equal to 5 ", The last place is even, for example,

Msgbox "Round (1.25, 1) =" & Round (1.25, 1)

The display result is 1.2, because the mantissa "is exactly equal to 5" after 1.2, the last position requirements of rounding are even, so the result is a decimal 1.2 rather than the large number 1.3

Msgbox "Round (1.25001, 1) =" & Round (1.25001, 1)

The display result is 1.3, because the mantissa "greater than 5" after 1.2, according to the four rounds

Msgbox "Round (1.35, 1) =" & Round (1.35, 1)

The display result is 1.4, because the mantissa after 1.2 is "accurate equal to 5", the last position requirements of rounding are even, so the result is a large number 1.4 rather than decimal 1.3

Concrete

Msgbox "Round (1.345, 2) =" & Round (1.345, 2)

Msgbox "Round (1.355, 2) =" & Round (1.355, 2)

The results of the display are 1.34 and 1.36, respectively.

I summed up the rules of the roundness of the "four hits into the five-way", "four" is less than five meaning, "six" is greater than five, "five" is the mantissa after the rounding position "is equally equal 5 ".

Reply to: Footballboy (Zheng Chuangbin) 2002-5-30 12:04:12 Score: 100

In addition, I think the perspective of statistics, "Since the Sixth 50%" is scientific than "round", it makes the result of rounding, and some are small, more average. Not like Since the time, it will be in the past, resulting in a large number.

For example: 1.15 1.25 1.35 1.45 = 5.2, if a decimal calculation is obtained

1.2 1.3 1.4 1.5 = 5.4

According to the "Si Zhixun 50%", 1.2 1.2 1.4 1.4 = 5.2, the results after the rounding can reflect the actual results

转载请注明原文地址:https://www.9cbs.com/read-95911.html

New Post(0)