Forum Discussion
pratikdarak21
Oct 05, 2023Iron Contributor
Rounding Issue
Hi, In PowerShell, Round (number, 4) method rounding 0.01275 to 0.0128 as 5 decimal having 5. But, 0.48865 not getting rounded to 0.4887 instead it is giving output as 0.4886. What causing p...
pratikdarak21
Oct 05, 2023Iron Contributor
randriksen_ What I have understood Round function is using Banker's rounding by default. Do you have well explained information/document around it so that I can understand more about.
randriksen_
Oct 05, 2023Brass Contributor
When there isn't a unique nearest integer, i.e. when the decimal part of a number is exactly 0.5, PowerShell rounds to the nearest even integer. This is known as banker's rounding or round-to-even. So, for example, [int] 1.5 would round to 2 but so would [int] 2.5 .
https://www.johndcook.com/blog/2008/05/19/rounding-and-integer-division-in-powershell/
https://www.johndcook.com/blog/2008/05/19/rounding-and-integer-division-in-powershell/