Opinions on trying to add a round decimal math function (SOLVED)

Does any one have any feelers on how hard this would be to implement?

Does anyone have any concerns about this that I might not realize?

Currently at the bottom of all of my scripts I add this line:

func round_decimal(number:float,decimal_place:int) → float: return round(number * pow(10.0, decimal_place)) / pow(10.0, decimal_place)

What this function does is it takes a float and rounds it to the nearest decimal place inputted by the user(me) and returns a rounded result to the nearest tenth or hundredth.

Why I need this is that the current round function doesn’t give you the ability to choose the nearest tenth or hundredths, it just rounds to a whole number

example of current round function:

var number: float = 15.222

number = round(number)

print(number) #this will change from 15.222 to 15

example of what I want to out of it:

var number: float = 15.222

number = round(number,1) #it will be like this round(number,optional flag)

print(number) #this will change from 15.222 to 15.2

do you think this is worth me trying to figure out?

how hard do you think this would this be to implement?

Use snappedf().

5 Likes

Thank you so much I had no idea about this. Thank you! :ok_hand: