Advertisement
BobMe

Area, Circumference,AA, CC calculator (Lua)

Apr 5th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. -- I got lazy in math so I made a calculator to literally solve all of my problems
  2.  
  3. Amount_of_decimals = 2
  4.  
  5. Radius = 0
  6. Diameter = 3
  7.  
  8.  
  9.  
  10. function removedec(number)
  11. num = tostring(number)
  12. for i=1,#num do
  13. if string.sub(num,i,i) == "." and string.sub(num,i+1,i+1) == "0" and string.sub(num,i+2,i+2) == "" then
  14. num = tonumber(string.sub(num,1,i-1))
  15. break
  16. end
  17. end
  18. return tonumber(num)
  19. end
  20.  
  21.  
  22. if Radius == 0 then
  23. Radius = removedec(Diameter/2)
  24. elseif Diameter == 0 then
  25. Diameter = Radius*2
  26. end
  27.  
  28. local g = "0."
  29.  
  30. for i=1,Amount_of_decimals do
  31. if i ~= Amount_of_decimals then
  32. g = g.."0"
  33. else
  34. g = g.."1"
  35. end
  36. end
  37. g=tonumber(g)
  38. ekk = g
  39.  
  40. EA = removedec(Radius^2)
  41. AA = removedec(EA*math.pi)
  42. AS = tostring(AA)
  43. for i=1,string.len(AA) do
  44. if string.sub(AA,i,i) == "." then
  45. if tonumber(string.sub(AA,i+Amount_of_decimals+1,i+Amount_of_decimals+1)) >= 5 then
  46. AA = tonumber(string.sub(AA,1,i+Amount_of_decimals))
  47. AA = AA+ekk
  48. else
  49. AA = tonumber(string.sub(AA,1,i+Amount_of_decimals))
  50. end
  51. end
  52. end
  53. EC = Diameter
  54. CC = removedec(EC*math.pi)
  55. for i=1,string.len(CC) do
  56. if string.sub(CC,i,i) == "." then
  57. if tonumber(string.sub(CC,i+Amount_of_decimals+1,i+Amount_of_decimals+1)) >= 5 then
  58. CC = tonumber(string.sub(CC,1,i+Amount_of_decimals))
  59. CC = CC+ekk
  60. else
  61. CC = tonumber(string.sub(CC,1,i+Amount_of_decimals))
  62. end
  63. end
  64. end
  65.  
  66. print("Radius: "..Radius.."\nDiameter: "..Diameter.."\nExact Area: "..EA.."\nDec Area: "..AA.."\nExact Circumference: "..EC.."\nDec Circumference: "..CC)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement