Advertisement
BobMe

More Chemistry Cheats

Nov 27th, 2019
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. -- im going to make a complete rounding function
  2.  
  3. function supernumber(y)
  4. local x = tonumber(y)
  5. if x > 0 and x < 10 then
  6. local sup = {"¹","²","³","⁴","⁵","⁶","⁷","⁸","⁹"}
  7. return sup[x]
  8. else
  9. return "⁰"
  10. end
  11. end
  12.  
  13. function supernumbers(x)
  14. local y = tostring(x)
  15. local k = ""
  16. for i=1,#y do
  17. k = k..supernumber(string.sub(y,i,i))
  18. end
  19. return k
  20. end
  21.  
  22. function round(number,deci)
  23. local num = tostring(number)
  24. local num2 = ""
  25. local num3 = ""
  26. local num4
  27. local savevar1 = ""
  28. for i=1,#num do
  29. if string.sub(num,i,i+1):lower() == "e+" then
  30. savevar1 = string.sub(num,i+2)
  31. num2 = string.sub(num,1,i-1)
  32. break
  33. end
  34. end
  35. if num2 ~= "" then num = num2 end
  36. for i=1,#num do
  37. if string.sub(num,i,i) == "." then
  38. num3 = tonumber(string.sub(num,deci+i+1,deci+i+1))
  39. num4 = tonumber(string.sub(num,deci+i,deci+i))
  40. if num3 == "" or num3 == nil then break end
  41. if num3 >= 5 then
  42. num = string.sub(num,1,i-1+deci)..tostring(num4+1)
  43. else
  44. num = string.sub(num,1,i-1+deci)..tostring(num4)
  45. end
  46. end
  47. end
  48. if savevar1 ~= "" then
  49. num = num.." * 10"..supernumbers(savevar1)
  50. end
  51. return num
  52. end
  53.  
  54. local moles = 0.2281928493
  55. local molar_mass = 44.0098 -- grams require molar_mass
  56. local atoms = 3
  57. local roundto = 2
  58.  
  59. local particles = moles*(6.02*10^23)
  60. local grams = moles*molar_mass
  61. local liters = moles*22.4
  62.  
  63. print("Particles: "..round(particles,roundto))
  64. print("Grams: "..round(grams,roundto))
  65. print("Liters: "..round(liters,roundto))
  66. print("Atoms: "..round(particles*atoms,roundto))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement