summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chat.lua24
1 files changed, 23 insertions, 1 deletions
diff --git a/chat.lua b/chat.lua
index a34086b..a4ba800 100644
--- a/chat.lua
+++ b/chat.lua
@@ -35,6 +35,28 @@ local function pad_c(s,width)
return string.rep(" ",hspace)..s
end
+
+local function round(n)
+ -- to nearest int
+ local f = math.floor(n)
+ if n>=f+0.5 then return math.ceil(n) else return f end
+end
+
+local function round_dp(n,dp)
+ local exp = 10^dp
+ return round(n*exp)/exp
+end
+
+local function sci(x)
+ local b = math.floor(math.log10(x))
+ local a = round_dp(x/10^b,2)
+ return a.."e"..b
+end
+
+local function maybe_sci(x)
+ if #tostring(x) >= scorewidth then return sci(x) else return x end
+end
+
-- drawing
-- lb
@@ -72,7 +94,7 @@ local function draw_lb(W,scores)
-- score
W.setTextColor(colors.red)
W.setCursorPos(w-scorewidth+1,i+1)
- W.write(pad_r(score,scorewidth))
+ W.write(pad_r(maybe_sci(score),scorewidth))
end
end