summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2022-08-04 03:11:47 +0100
committerubq323 <ubq323@ubq323.website>2022-08-04 03:11:47 +0100
commitce59711d67658bf550772158087923db5a716d51 (patch)
tree92ae84d553ac602af28972c98b2d879ae37bcc78
parent1a0ef93928bd16c98868c1c1a4492c05529fd54e (diff)
chat
-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