Hi..Sorry for late reply ...Let me tell you where I needed this type of approach...
I am working on a plan management tool where user has to give their estimate..
user can give estimate like 8.4,8.6 etc...
It means 8 days and .4 of another day....
Now when we generate a report client needed x.4=>x , x.6=>x+1 , x.5=>x+1
So I tried conver.toint32 ...but as I told it has its problem which didnt suit my set of decimals
So we used Math.Round(8.5,MidpointRounding.AwayFromZero)
now (int)(mynumber+0.5d) is another way to do the same ....
while doing this I found this way to be very flexible...
Say tommorow my client say they need x.4=>x , x.6=>x+1 , x.5=>x which I think is not unlikely
Please let me know how will you do it if you are aware of some other better approach ?
Just writing that its just a quick fix will not help me to learn(for which I am in this forum :) )
Also @dishdy Well, satyajit's technique will work if you are only dealing with numbers with exactly one digit after the decimal point. Thus it is a very limited approach.
8.566 => 9 ... using (int)(mynumber+0.5d)
8.566 => 8 ... using (int)(mynumber+0.4d)
is it wrong ? Please let me know ...
commented on Jun 19 2012 1:38AM