public double halfRound(double val)
{
double ten = val * 10;
double key = ten % 10;
if( key>=5 || key==0 )
return Math.Round( val, MidpointRounding.AwayFromZero);
else
return Math.Round(val, MidpointRounding.AwayFromZero)+0.5;
}
這樣子就達成目的了!
halfRound(1.2) => 1.5
halfRound(1.6) => 2
沒有留言:
張貼留言