static int round ( int value , int precision , int significantDigits ) { if ( precision > 0 ) { value = ( value + precision / 2 ) / precision * precision ; } if ( significantDigits > 0 ) { int forRounding = value ; int precisionMax = ( int ) Math . pow ( 10 , significantDigits ) ; int multiplier = 1 ; while ( value > precisionMax ) { forRounding = value ; multiplier *= 10 ; value /= 10 ; } if ( forRounding % 10 >= 5 ) { value ++ ; } value *= multiplier ; } return value ; }
Round integer number by applying precision and maximum significant digits .