Util: add function "round_decimal" to round to a decimal point

0.00001, decimal 2 -> 0.00
reviewable/pr11592/r4
hasezoey 2 months ago
parent 14d027a036
commit 2e926f0c11
No known key found for this signature in database
GPG Key ID: 9F8C99E834CC54FB

@ -1537,4 +1537,12 @@ function util.wrapMethod(target_table, target_field_name, new_func, before_callb
return wrapped
end
-- Round a given "num" to the decimal points of "points"
-- (i.e. `round_decimal(0.000000001, 2)` will yield `0.00`)
function util.round_decimal(num, points)
local op = 10 ^ points
return math.floor(num * op) / op
end
return util

Loading…
Cancel
Save