こんにちは
UiPath Studio 2025.0.161STS Community editionのユーザーです。
以前有識者の方が、倍精度数値の小数点以下第一位の四捨五入方法は
Math.Round(21252/111,MidpointRounding.AwayFromZero)
だとおっしゃっていましたが、
Math.Round(21252/111)
を実行しても出力パネルに出た結果は同じ191でした。
後者を使うと何か問題が発生しますか?
こんにちは
UiPath Studio 2025.0.161STS Community editionのユーザーです。
以前有識者の方が、倍精度数値の小数点以下第一位の四捨五入方法は
Math.Round(21252/111,MidpointRounding.AwayFromZero)
だとおっしゃっていましたが、
Math.Round(21252/111)
を実行しても出力パネルに出た結果は同じ191でした。
後者を使うと何か問題が発生しますか?
Hi @gorby
They are different from each other.
for your input 21252/111, it gives same output because the answer is 191.45.
Math.Round(21252/111)
Uses MidpointRounding.ToEven to round off by Default. Which means, if it is 0.5 and greater, it will be rounded off to the Even Number.
Math.Round(21252/111,MidpointRounding.AwayFromZero)
Uses MidpointRounding.AwayFromZero, which means, if it is 0.5, it will be rounded to the greater value.
Here is the screenshot which will explain better:
Here is the explanation from Official Documentation from Microsoft:
If this answers your query, Do mark it as a solution
Happy Automation
Math.Round(21252/111,MidpointRounding.AwayFromZero)
uses Rounding away from zero
Math.Round(21252/111)
uses Rounding to nearest even
Rounding away from zero
Midpoint values are rounded to the next number away from zero. For example, 3.75 rounds to 3.8, 3.85 rounds to 3.9, -3.75 rounds to -3.8, and -3.85 rounds to -3.9. This form of rounding is represented by the MidpointRounding.AwayFromZero enumeration member.
Rounding to nearest even, or banker’s rounding
Midpoint values are rounded to the nearest even number. For example, both 3.75 and 3.85 round to 3.8, and both -3.75 and -3.85 round to -3.8. This form of rounding is represented by the MidpointRounding.ToEven enumeration member.
こんにちは
計算のアルゴリズムが異なりますので結果が異なるケースが出てきます。
例えば
Math.Round(21252/168,MidpointRounding.AwayFromZero)
と
Math.Round(21252/168)
を比較いただければと思います。
承知致しました。
小数点第一位切り上げと切り捨ての場合は、単純に、
Math.Ceiling(21252/111)
Math.Floor(21252/111)
で問題ないでしょうか?
この桁数レベルの数値演算でしたら、基本的には問題ないと思います。
Hi @gorby
Here is an in-depth Explanation:
If you observe the below screenshot for Math.Round():
If you observe the below screenshot for Math.Round(value,MidpointRounding.AwayFromZero)
If you observe the below screenshot for Math.Ceiling(), It considers the Higher Value for any decimal value greater than .0
If you observe the below screenshot for Math.Floor(), It considers the Lower Value for any decimal value greater than .0
If this clears your Query completely, Do mark it as a solution.
Happy Automation