Merge pull request #246 from IdrisDose/main

feat (Functions/Math): Added Precision Rounding so that people can round to nearest decimal efficiently.
This commit is contained in:
Kakarot
2021-10-31 07:50:27 -06:00
committed by GitHub
2 changed files with 38 additions and 0 deletions
+19
View File
@@ -629,3 +629,22 @@ function QBCore.Functions.SetVehicleProperties(vehicle, props)
end
end
end
-- Extra Math Functions
-- Math Rounding Credits: http://lua-users.org/wiki/SimpleRound
function QBCore.Functions.Math.Sign(v)
return (v >= 0 and 1) or -1
end
-- Math Rounding Credits: http://lua-users.org/wiki/SimpleRound
-- Usage:
-- QBCore.Functions.Math.Round(119.68, 0.01) = 119.68
-- QBCore.Functions.Math.Round(119.68, 0.1) = 119.7
-- QBCore.Functions.Math.Round(119.68) = 120
-- QBCore.Functions.Math.Round(119.68, 100) = 100
-- QBCore.Functions.Math.Round(119.68, 1000) = 0
function QBCore.Functions.Math.Round(v, bracket)
bracket = bracket or 1
return QBCore.Functions.Math.Sign(v/bracket + QBCore.Functions.Math.Sign(v) * 0.5) * bracket
end
+19
View File
@@ -299,3 +299,22 @@ function QBCore.Functions.IsLicenseInUse(license)
end
return false
end
-- Extra Math Functions
-- Math Rounding Credits: http://lua-users.org/wiki/SimpleRound
function QBCore.Functions.Math.Sign(v)
return (v >= 0 and 1) or -1
end
-- Math Rounding Credits: http://lua-users.org/wiki/SimpleRound
-- Usage:
-- QBCore.Functions.Math.Round(119.68, 0.01) = 119.68
-- QBCore.Functions.Math.Round(119.68, 0.1) = 119.7
-- QBCore.Functions.Math.Round(119.68) = 120
-- QBCore.Functions.Math.Round(119.68, 100) = 100
-- QBCore.Functions.Math.Round(119.68, 1000) = 0
function QBCore.Functions.Math.Round(v, bracket)
bracket = bracket or 1
return QBCore.Functions.Math.Sign(v/bracket + QBCore.Functions.Math.Sign(v) * 0.5) * bracket
end