How to align game objects to a grid?

I’m making my ship builder test right now. I’m almost done but have ran into a problem I can’t google because I really don’t know how to word it correctly to get me what I want. I want to be able to click and it adds a new ship part, but I can’t just let it add a new part without having a grid system because then lining up certain parts of a ship would be almost impossible. So, how would I do it? I’m just trying to get it so that when I hit my mouse button instead of having it add the object right at the exact x and y coords of the mouse, but to have it on a 32 x 32 grid without programming some advanced tile based system.

Heres my current code:


int x = input.getMouseX();
int y = input.getMouseY();
		
//ADDING Ship parts
if(input.isMouseButtonDown(0)) {
	sc.addPart(new BasicPart(x, y));
}

x = ((int) x/32) *32
y = ((int) y/32) *32

IK there was a simple algorithm. Thanks so much nitro! I will make this little engine thing open source don’t worry.

[quote]I can’t google because I really don’t know how to word it correctly
[/quote]
This is often refered to as “Round to nearest multiple of ___” I am oblivious to any proper mathematical name for it.

Related is the Floor Function. Also on that page are other arithmetic goodies. java.lang.Math includes floor() and related as well.