12,244,802 members (48,712 online)
Rate this:
See more:
my code is
Int64 i = ((Int64)Math.Round(Convert.ToDecimal(dr["CHARGE"]) / 10,1,MidpointRounding.AwayFromZero)) * 10;

its working but one exception is
For 100's (eg: 100,200,300 etc), if we set charge as 105,205,etc its not rounding properly. Expected result: 110,120,130 etc, but now its displaying as 100,200,300 etc.

how can avoid this error ?

this is my requirement

95 to 104.9 --> 100
105 to 114.9 --> 110

Posted 9-Jan-13 22:00pm
Edited 9-Jan-13 22:13pm
v2

Rate this:

## Solution 2

Try:
public int RoundOff (Decimal valueToRound)
{
return ((int)Math.Round(valueToRound / 10.0)) * 10;
}
v2
Rate this:

## Solution 3

if (Convert.ToDecimal(x % 10) == 5)
{
x = x + 1;

}
Int64 i = ((Int64)Math.Round(Convert.ToDecimal(x) / 10)) * 10;
Rate this:

## Solution 4

var ii = Math.Round(Convert.ToDecimal((104.9 + 0.0000001) / 10.00)) * 10 ;
Rate this:

## Solution 5

public int round(float value)
{
return (((int)value + 5) / 10) * 10;
}
Rate this:

## Solution 1

Try rounding with below line.

Int64 i = ((Int64)Math.Round(Convert.ToDecimal(dr["CHARGE"])/ 10,MidpointRounding.AwayFromZero)) * 10;

Top Experts
Last 24hrsThis month
 Jochen Arndt 385 George Jonsson 335 OriginalGriff 319 ppolymorphe 296 BillWoodruff 240
 OriginalGriff 609 George Jonsson 340 Jochen Arndt 265 BillWoodruff 240 ppolymorphe 146