Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I round numbers in a Number Value to be specific?

Asked by
azobo 4
3 years ago

Hello. I am trying to make an advanced airplane model, and it will have similar instruments to the ones on a real life plane. I am right now making the altimeter, but I ran into a roadblock. I have gotten the altimeter to say the part's height, but I cant get it to round. This is a very crucial part to the airplane because once autopilot is put in, it will need to have the altimeter numbers rounded as a whole. (Please note the altimeter's height is recorded through a number value).

Currently, the altimeter works like this: Altitude: 14597.826

How I need it to work: Altitude: 14597

Thanks

1 answer

Log in to vote
0
Answered by
azobo 4
3 years ago

I solved it myself with a script. Here it is: ActualAltitude is what the altimeter is showing without rounding while true do local ActualAltitude = script.Parent.Value function Round(Number, Decimals) Decimals = (Decimals > 0 and Decimals or 0) Number = Number*(10^Decimals) local rNum, Dec = math.modf(Number) if Dec >= .5 then rNum = rNum + 1 end return rNum/(10^Decimals) end

script.Parent.Value = (Round(ActualAltitude, 0))
wait()

end

0
You could just use math.floor to round it down, or math.ceil to round it up. Rinpix 639 — 3y
Ad

Answer this question