Rounding Numbers

Currently working on fixing a speed radar script below is what I have to catch speed

local TargetVehicleInfo = { Name = GetDisplayNameFromVehicleModel(GetEntityModel(TargetVehicle)), Plate = GetVehicleNumberPlateText(TargetVehicle), Speed = (GetEntitySpeed(TargetVehicle)*2.23694), Insurance = GetVehicleInsurance(GetVehicleNumberPlateText(TargetVehicle)), Registration = GetVehicleRegistration(GetVehicleNumberPlateText(TargetVehicle)) }

My question is how do I round off the radar to the nearest whole number instead of going out like 10 decimal places like it currently is? This is what is there, is there anybody that can help me fix it by any chance? Thank you!

function RoundNumber(num, numRoundNumber)
  local mult = 10^(numRoundNumber or 0)
  return math.floor(num * mult + 0.5) / mult
end
local TargetVehicleInfo = { Name = GetDisplayNameFromVehicleModel(GetEntityModel(TargetVehicle)), Plate = GetVehicleNumberPlateText(TargetVehicle), Speed = RoundNumber(GetEntitySpeed(TargetVehicle)*2.23694), Insurance = GetVehicleInsurance(GetVehicleNumberPlateText(TargetVehicle)), Registration = GetVehicleRegistration(GetVehicleNumberPlateText(TargetVehicle)) }

I am lost here, isn’t this just what I wrote?

From:

Speed = (GetEntitySpeed(TargetVehicle)*2.23694)

To:

Speed = RoundNumber(GetEntitySpeed(TargetVehicle)*2.23694)

Should I remove

function RoundNumber(num, numRoundNumber)
  local mult = 10^(numRoundNumber or 0)
  return math.floor(num * mult + 0.5) / mult
end

entirely then?

imo you should remove it and try just:

Speed = math.floor(GetEntitySpeed(TargetVehicle)*2.23694)

Should work fine, and 4 lines less. :smiley:

But if you want use RoundNumber functions, how you can delete RoundNumber function? XD

Amazing, thank you for your help

wtf?

string.format("%.2f", speed) when displaying

1 Like