How to round a position to the nearest 10 [Godot 3.0 RC3]

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By HarryCourt
:warning: Old Version Published before Godot 3 was released.

I have a script where the mouse drags an item. However, I want that script to be able to round to the nearest 10.

For example;
10 by 10: Correct
260 by 570: Correct
10 by 15: Incorrect

Here is the script:

func dragItem():
	isDragging = true
	var mousePos = get_global_mouse_position()
	mousePos = mousePos.floor()

What can I do to make sure it always rounds to the nearest tenth?

:bust_in_silhouette: Reply From: mollusca

GDScript has the handy stepify(float s, float step) function. For example:

var mousePos = get_global_mouse_position()
self.set_position(Vector2(stepify(mousePos.x, 10), stepify(mousePos.y, 10)))
:bust_in_silhouette: Reply From: aidave

In Godot 4 this is now a function called snapped()