标签:
英语不好, 见谅。
1 float myRound (float src, int idx)
2 {
3 //move idx numbers right of the point
4 //to the left
5 for (int i = idx; i--;) {
6 src *= 10;
7 }
8
9 //get left part of src
10 float dest = static_cast<int>(src);
11
12 //if the number behind the idx
13 //are larger than 5, then article idx plus 1
14 if (src >= dest + 0.5) {
15 dest += 1;
16 }
17
18 //right nuber back to home
19 for (int i = idx; i--;) {
20 dest /= 10;
21 }
22 return std::move (dest);
23 }
标签:
原文地址:http://www.cnblogs.com/wuOverflow/p/4253886.html