# 关于C#：为什么四舍五入时.5变成1.0？应该不是0.5吗？

2021-04-27

## Why does .5 become 1.0 when rounding? Shouldn't it be 0.5?

 12345678910111213141516171819 while (c < .9) {     std::cin >> c;     std::cout <<"\ c =" << c << '\ ';     array.push_back(c);     c = round ((c *10)/10);     std::cout <<"After rounding, c =" << c << '\ '; } std::cout <<"\ Size of the vector \'array\' =" << array.size() << '\ '; for (int i = 0; i < array.size(); i ++ ) {     std::cout <<"\ array[" << i <<"] =" << array[i] << std::endl; }

 123456789101112131415161718192021222324252627282930313233 .1 c = 0.1 After rounding, c = 0 .2 c = 0.2 After rounding, c = 0 .3 c = 0.3 After rounding, c = 0 .4 c = 0.4 After rounding, c = 0 .5 c = 0.5 After rounding, c = 1 Size of the vector 'array' = 5 array[0] = 0.1 array[1] = 0.2 array[2] = 0.3 array[3] = 0.4 array[4] = 0.5 Program ended with exit code: 0

Computes the nearest integer value to arg (in floating-point format), rounding halfway cases away from zero, regardless of the current rounding mode.