From 2ddb317dd311f4f099259a273225cac5695b13cf Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Fri, 9 Sep 2022 17:04:36 -0400 Subject: [PATCH] FIX rounding error in percent labels --- src/modules/common.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/modules/common.lua b/src/modules/common.lua index e5ee797..f0d4005 100644 --- a/src/modules/common.lua +++ b/src/modules/common.lua @@ -121,8 +121,14 @@ return function(config) ) end + -- a conventional rounding function that behaves the way most humans were + -- taught in preschool + local _round = function(x) + return math.floor(x + 0.5) + end + local _format_percent_label = function(_) - return function(z) return __string_format('%i%%', math.floor(z * 100)) end + return function(z) return __string_format('%i%%', _round(z * 100)) end end local _format_percent_maybe = function(z)