程式語法ASPRound 及 FormatNumber 四捨五入的區別 - ASP 程式語法

Round & FormatNumber 四捨五入的區別

VBScript Round() 為四捨五入函數,但是 Round() 四捨五入為近偶取整,與我們平常用的並不一樣,平時是以大於等於 5 的數值進位、小於 5 的數值捨去。FormatNumber() 的值比較符合平常用的值。使用 Round() 近偶取整則於偶數才進位與 FormatNumber() 四捨五入有差異由下表來分析差異點。

運算的數值Round()FormatNumber()差異處
0.1Round(0.1, 0) = 0FormatNumber(0.1, 0) = 0-
0.2Round(0.2, 0) = 0FormatNumber(0.2, 0) = 0-
0.3Round(0.3, 0) = 0FormatNumber(0.3, 0) = 0-
0.4Round(0.4, 0) = 0FormatNumber(0.4, 0) = 0-
0.5Round(0.5, 0) = 0FormatNumber(0.5, 0) = 1差異處
0.6Round(0.6, 0) = 1FormatNumber(0.6, 0) = 1-
0.7Round(0.7, 0) = 1FormatNumber(0.7, 0) = 1-
0.8Round(0.8, 0) = 1FormatNumber(0.8, 0) = 1-
0.9Round(0.9, 0) = 1FormatNumber(0.9, 0) = 1-
1.0Round(1.0, 0) = 1FormatNumber(1.0, 0) = 1-
1.1Round(1.1, 0) = 1FormatNumber(1.1, 0) = 1-
1.2Round(1.2, 0) = 1FormatNumber(1.2, 0) = 1-
1.3Round(1.3, 0) = 1FormatNumber(1.3, 0) = 1-
1.4Round(1.4, 0) = 1FormatNumber(1.4, 0) = 1-
1.5Round(1.5, 0) = 2FormatNumber(1.5, 0) = 2-
1.6Round(1.6, 0) = 2FormatNumber(1.6, 0) = 2-
1.7Round(1.7, 0) = 2FormatNumber(1.7, 0) = 2-
1.8Round(1.8, 0) = 2FormatNumber(1.8, 0) = 2-
1.9Round(1.9, 0) = 2FormatNumber(1.9, 0) = 2-
2.0Round(2.0, 0) = 2FormatNumber(2.0, 0) = 2-
2.1Round(2.1, 0) = 2FormatNumber(2.1, 0) = 2-
2.2Round(2.2, 0) = 2FormatNumber(2.2, 0) = 2-
2.3Round(2.3, 0) = 2FormatNumber(2.3, 0) = 2-
2.4Round(2.4, 0) = 2FormatNumber(2.4, 0) = 2-
2.5Round(2.5, 0) = 2FormatNumber(2.5, 0) = 3差異處
2.6Round(2.6, 0) = 3FormatNumber(2.6, 0) = 3-
2.7Round(2.7, 0) = 3FormatNumber(2.7, 0) = 3-
2.8Round(2.8, 0) = 3FormatNumber(2.8, 0) = 3-
2.9Round(2.9, 0) = 3FormatNumber(2.9, 0) = 3-
3.0Round(3.0, 0) = 3FormatNumber(3.0, 0) = 3-
3.1Round(3.1, 0) = 3FormatNumber(3.1, 0) = 3-
3.2Round(3.2, 0) = 3FormatNumber(3.2, 0) = 3-
3.3Round(3.3, 0) = 3FormatNumber(3.3, 0) = 3-
3.4Round(3.4, 0) = 3FormatNumber(3.4, 0) = 3-
3.5Round(3.5, 0) = 4FormatNumber(3.5, 0) = 4-
3.6Round(3.6, 0) = 4FormatNumber(3.6, 0) = 4-
3.7Round(3.7, 0) = 4FormatNumber(3.7, 0) = 4-
3.8Round(3.8, 0) = 4FormatNumber(3.8, 0) = 4-
3.9Round(3.9, 0) = 4FormatNumber(3.9, 0) = 4-
4.0Round(4.0, 0) = 4FormatNumber(4.0, 0) = 4-
4.1Round(4.1, 0) = 4FormatNumber(4.1, 0) = 4-
4.2Round(4.2, 0) = 4FormatNumber(4.2, 0) = 4-
4.3Round(4.3, 0) = 4FormatNumber(4.3, 0) = 4-
4.4Round(4.4, 0) = 4FormatNumber(4.4, 0) = 4-
4.5Round(4.5, 0) = 4FormatNumber(4.5, 0) = 5差異處
4.6Round(4.6, 0) = 5FormatNumber(4.6, 0) = 5-
4.7Round(4.7, 0) = 5FormatNumber(4.7, 0) = 5-
4.8Round(4.8, 0) = 5FormatNumber(4.8, 0) = 5-
4.9Round(4.9, 0) = 5FormatNumber(4.9, 0) = 5-
5.0Round(5.0, 0) = 5FormatNumber(5.0, 0) = 5-
5.1Round(5.1, 0) = 5FormatNumber(5.1, 0) = 5-
5.2Round(5.2, 0) = 5FormatNumber(5.2, 0) = 5-
5.3Round(5.3, 0) = 5FormatNumber(5.3, 0) = 5-
5.4Round(5.4, 0) = 5FormatNumber(5.4, 0) = 5-
5.5Round(5.5, 0) = 6FormatNumber(5.5, 0) = 6-
5.6Round(5.6, 0) = 6FormatNumber(5.6, 0) = 6-
5.7Round(5.7, 0) = 6FormatNumber(5.7, 0) = 6-
5.8Round(5.8, 0) = 6FormatNumber(5.8, 0) = 6-
5.9Round(5.9, 0) = 6FormatNumber(5.9, 0) = 6-
6.0Round(6.0, 0) = 6FormatNumber(6.0, 0) = 6-
6.1Round(6.1, 0) = 6FormatNumber(6.1, 0) = 6-
6.2Round(6.2, 0) = 6FormatNumber(6.2, 0) = 6-
6.3Round(6.3, 0) = 6FormatNumber(6.3, 0) = 6-
6.4Round(6.4, 0) = 6FormatNumber(6.4, 0) = 6-
6.5Round(6.5, 0) = 6FormatNumber(6.5, 0) = 7差異處
6.6Round(6.6, 0) = 7FormatNumber(6.6, 0) = 7-
6.7Round(6.7, 0) = 7FormatNumber(6.7, 0) = 7-
6.8Round(6.8, 0) = 7FormatNumber(6.8, 0) = 7-
6.9Round(6.9, 0) = 7FormatNumber(6.9, 0) = 7-
7.0Round(7.0, 0) = 7FormatNumber(7.0, 0) = 7-
7.1Round(7.1, 0) = 7FormatNumber(7.1, 0) = 7-
7.2Round(7.2, 0) = 7FormatNumber(7.2, 0) = 7-
7.3Round(7.3, 0) = 7FormatNumber(7.3, 0) = 7-
7.4Round(7.4, 0) = 7FormatNumber(7.4, 0) = 7-
7.5Round(7.5, 0) = 8FormatNumber(7.5, 0) = 8-
7.6Round(7.6, 0) = 8FormatNumber(7.6, 0) = 8-
7.7Round(7.7, 0) = 8FormatNumber(7.7, 0) = 8-
7.8Round(7.8, 0) = 8FormatNumber(7.8, 0) = 8-
7.9Round(7.9, 0) = 8FormatNumber(7.9, 0) = 8-
8.0Round(8.0, 0) = 8FormatNumber(8.0, 0) = 8-
8.1Round(8.1, 0) = 8FormatNumber(8.1, 0) = 8-
8.2Round(8.2, 0) = 8FormatNumber(8.2, 0) = 8-
8.3Round(8.3, 0) = 8FormatNumber(8.3, 0) = 8-
8.4Round(8.4, 0) = 8FormatNumber(8.4, 0) = 8-
8.5Round(8.5, 0) = 8FormatNumber(8.5, 0) = 9差異處
8.6Round(8.6, 0) = 9FormatNumber(8.6, 0) = 9-
8.7Round(8.7, 0) = 9FormatNumber(8.7, 0) = 9-
8.8Round(8.8, 0) = 9FormatNumber(8.8, 0) = 9-
8.9Round(8.9, 0) = 9FormatNumber(8.9, 0) = 9-
9.0Round(9.0, 0) = 9FormatNumber(9.0, 0) = 9-
9.1Round(9.1, 0) = 9FormatNumber(9.1, 0) = 9-
9.2Round(9.2, 0) = 9FormatNumber(9.2, 0) = 9-
9.3Round(9.3, 0) = 9FormatNumber(9.3, 0) = 9-
9.4Round(9.4, 0) = 9FormatNumber(9.4, 0) = 9-
9.5Round(9.5, 0) = 10FormatNumber(9.5, 0) = 10-
9.6Round(9.6, 0) = 10FormatNumber(9.6, 0) = 10-
9.7Round(9.7, 0) = 10FormatNumber(9.7, 0) = 10-
9.8Round(9.8, 0) = 10FormatNumber(9.8, 0) = 10-
9.9Round(9.9, 0) = 10FormatNumber(9.9, 0) = 10-

Round()FormatNumber() Rounding 主要差異處比較

FormatNumber() 函數

FormatNumber(2.5,0)

3

FormatNumber(4.5,0)

5

FormatNumber(6.5,0)

7

FormatNumber(8.5,0)

9

Round() 函數

Round(2.5)

2

Round(4.5)

4

Round(6.5)

6

Round(8.5)

8


CodingASP 四捨五入函數之使用則依照需求來選擇 Round()FormatNumber() 函數。

How To Implement Custom Rounding Procedures (support.microsoft.com)

Modification in