diff options
author | ubq323 <ubq323@ubq323.website> | 2022-08-04 03:11:47 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2022-08-04 03:11:47 +0100 |
commit | ce59711d67658bf550772158087923db5a716d51 (patch) | |
tree | 92ae84d553ac602af28972c98b2d879ae37bcc78 | |
parent | 1a0ef93928bd16c98868c1c1a4492c05529fd54e (diff) |
chat
-rw-r--r-- | chat.lua | 24 |
1 files changed, 23 insertions, 1 deletions
@@ -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 |