Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function round(number,deci)
- local num = tostring(number)
- local num2 = ""
- local num3 = ""
- local num4
- local num5
- local savevar1 = ""
- if deci ~= 0 then
- 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
- else
- for i=1,#num do
- if string.sub(num,i,i) == "." then
- num3 = string.sub(num,i+1,i+1)
- num5 = string.sub(num,i-1,i-1)
- num4 = i
- break
- end
- end
- num3 = tonumber(num3)
- num5 = tonumber(num5)
- if num3 >= 5 then
- num = string.sub(num,1,num4-2)..tostring(num5+1)
- else
- num = string.sub(num,1,num4)
- end
- num = tonumber(num)
- end
- return num
- end
- round(10.27854,2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement