Rounding off a number

  • Thread starter Thread starter Prabhakar
  • Start date Start date
P

Prabhakar

Hi all,
I have a function that does some calculations and returns
a value.Before i return i need to round it off to it's
nearest whole number based on the value in the hundreth
position i.e. for example if the value is 1042 i need to
return 1000 and if the value is 1090 i need to return
1050.System.Math.Round() is not allowing me to do this.
Any help in this reagards is widely appreciated.

Thanks
Prabhakar
 
Prabhakar said:
I have a function that does some calculations and returns
a value.Before i return i need to round it off to it's
nearest whole number based on the value in the hundreth
position i.e. for example if the value is 1042 i need to
return 1000 and if the value is 1090 i need to return
1050.System.Math.Round() is not allowing me to do this.
Any help in this reagards is widely appreciated.

Why would you return 1050 for 1090 but not for 1042? Is the idea that
you *always* round down, but only to multiples of 50? If so, just:

int rounded = (original/50)*50;

should work. You should decide exactly what you want it to do for
negative numbers if they might crop up though.
 
Thanks.I have to return 1050 for 1090 because the value
in the hundredth position is greater than 5 and for 1042
i have to return 1000 because the value in the hundredth
position is less than 5.I think your suggestion should be
fine.Will take care of the croping of the negative
numbers.

thanks
Prabhakar
 
Back
Top