java - Zero the 3 lowest digits of an int -


i want 0 3 lowest digits of int. e.g. assume int 1023, simplest , efficient method clearlower such that:

clearlower(1023) == 1000 

if 1000 power of 2 easy using bitwise "and" operator, not case. know 2 possibilities:

public int clearlower(int a) {     return (a/1000)*1000; }  public int clearlower2(int a) {     return - a%1000; } 

is there easier and/or more efficient way?


Comments