local fmts = { ["zł"] = "%.2f %s", l = "%.2f %s", km = "%.1f %s", } local function fmt (value, unit) return (fmts[unit] or "%.1f"):format(value, unit) end local last_milage = 0 local function relative (kilometres) return last_milage + kilometres end local function fill (id, date, time, milage, fuel, cost, volume) if last_milage > milage then error "new milage may not be less than the previous" end last_milage = milage print(id, date, time, fmt(last_milage, "km"), fuel, fmt(cost, "zł"), fmt(volume, "l")) end return {fill=fill, relative=relative}