FactoryPlanner icon indicating copy to clipboard operation
FactoryPlanner copied to clipboard

Optimize format_number and format_SI_value

Open ClaudeMetz opened this issue 1 year ago • 0 comments

Also, maaaybe they can accomodate a functionality to format the same number to different precisions in one go, which is needed in several spots. Also add thousands-place separators to the format function. Also give an indication whether the number was rounded/cut off or not (~)

Curi proposes this method for display formatting:

local function number_to_string_with_precision(number, precision)
    local result = tostring(number)
    if precision > 0 then
        local rounded = format(format('%%.%if', precision), number)
        if strlen(rounded) < strlen(result) then
            result = rounded
        end
    end
    return result
end

ClaudeMetz avatar Jul 26 '23 07:07 ClaudeMetz