Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- superscript generator (for numbers)
- function to_super(x)
- local function number_to_super(x)
- local y = tonumber(x)
- if y ~= nil then
- local tab = {"¹","²","³","⁴","⁵","⁶","⁷","⁸","⁹"}
- if tab[y] ~= nil then
- return tab[y]
- else
- return "⁰"
- end
- end
- end
- local y = tostring(x)
- local str = ""
- for i=1,#y do
- str = str..number_to_super(string.sub(y,i,i))
- end
- return str
- end
- -- im going to make a complete rounding function
- function round(number,deci)
- local num = tostring(number)
- local num2 = ""
- local num3 = ""
- local num4
- local savevar1 = ""
- for i=1,#num do
- if string.sub(num,i,i+1):lower() == "e+" then
- savevar1 = string.sub(num,i+2)
- num2 = string.sub(num,1,i-1)
- break
- end
- end
- if num2 ~= "" then num = num2 end
- for i=1,#num do
- if string.sub(num,i,i) == "." then
- num3 = tonumber(string.sub(num,deci+i+1,deci+i+1))
- num4 = tonumber(string.sub(num,deci+i,deci+i))
- if num3 == "" or num3 == nil then break end
- if num3 >= 5 then
- num = string.sub(num,1,i-1+deci)..tostring(num4+1)
- else
- num = string.sub(num,1,i-1+deci)..tostring(num4)
- end
- end
- end
- if savevar1 ~= "" then
- num = num.." * 10"..to_super(savevar1)
- end
- return num
- end
- print(round((8213.2791),2));print(round((9.32874723 * 17^39),2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement