Advertisement
BobMe

this round function thing good good

Mar 31st, 2020
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. function round(number,deci)
  2. local num = tostring(number)
  3. local num2 = ""
  4. local num3 = ""
  5. local num4
  6. local num5
  7. local savevar1 = ""
  8. if deci ~= 0 then
  9. if num2 ~= "" then num = num2 end
  10. for i=1,#num do
  11. if string.sub(num,i,i) == "." then
  12. num3 = tonumber(string.sub(num,deci+i+1,deci+i+1))
  13. num4 = tonumber(string.sub(num,deci+i,deci+i))
  14. if num3 == "" or num3 == nil then break end
  15. if num3 >= 5 then
  16. num = string.sub(num,1,i-1+deci)..tostring(num4+1)
  17. else
  18. num = string.sub(num,1,i-1+deci)..tostring(num4)
  19. end
  20. end
  21. end
  22. else
  23. for i=1,#num do
  24. if string.sub(num,i,i) == "." then
  25. num3 = string.sub(num,i+1,i+1)
  26. num5 = string.sub(num,i-1,i-1)
  27. num4 = i
  28. break
  29. end
  30. end
  31. num3 = tonumber(num3)
  32. num5 = tonumber(num5)
  33. if num3 >= 5 then
  34. num = string.sub(num,1,num4-2)..tostring(num5+1)
  35. else
  36. num = string.sub(num,1,num4)
  37. end
  38. num = tonumber(num)
  39. end
  40. return num
  41. end
  42.  
  43. round(10.27854,2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement