我需要增量如下:
| 輸入 | 圓形 |
|---|---|
| 10.00 | 10.50 |
| 10.10 | 10.50 |
| 10.20 | 10.50 |
| 10.30 | 10.50 |
| 10.40 | 10.50 |
| 10.50 | 10.50 |
| 10.60 | 11.00 |
| 10.70 | 11.00 |
| 10.80 | 11.00 |
| 10.90 | 11.00 |
如何以最簡單的方式計算結果
uj5u.com熱心網友回復:
這是您的資料:
var data = new[]
{
new { input = 10.00, expected = 10.50 },
new { input = 10.10, expected = 10.50 },
new { input = 10.20, expected = 10.50 },
new { input = 10.30, expected = 10.50 },
new { input = 10.40, expected = 10.50 },
new { input = 10.50, expected = 10.50 },
new { input = 10.60, expected = 11.00 },
new { input = 10.70, expected = 11.00 },
new { input = 10.80, expected = 11.00 },
new { input = 10.90, expected = 11.00 },
};
向上舍入到最接近的正常方法0.5是使用Math.Ceiling(input * 2.0) / 2.0).
我會這樣做:
var output =
data
.Select(x => new
{
x.input,
x.expected,
actual = Math.Ceiling(x.input * 2.0) / 2.0
});
這給了我:

我確實注意到10保持不變,10而不是10.5按照您的要求。我想知道你是否把這個要求弄錯了,因為10.5沒有四舍五入?
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/495278.html
標籤:。网
