MA[S]RIY Posted November 3, 2017 Posted November 3, 2017 السلام عليكم كيف احول متغير رقمي عشري ألي رقمي صحيح يعني في متغير قيمته رقم عشري مثال 56.4 كيف اخلي لو القيمه العشريه اصغر من 0.5 يحط المتغير 56 و لو القيمه العشريه اكبر من 0.5 يحط المتغير 57 كيف ؟
MA[S]RIY Posted November 3, 2017 Author Posted November 3, 2017 انا شوفت يوزفل فنكشن لطلبي بس ادور الحين مو لاقيه ؟
King12 Posted November 3, 2017 Posted November 3, 2017 function math.round(number, decimals, method) decimals = decimals or 0 local factor = 10 ^ decimals if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor else return tonumber(("%."..decimals.."f"):format(number)) end end usage: math.round(10.4) -- output: 10 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now