def to_reasonable_unit(value, units, round_digits=<NUM_LIT:2>):
def to_unit(unit):<EOL><INDENT>return float(value) / unit[<NUM_LIT:1>]<EOL><DEDENT>exponents = [abs(Decimal(to_unit(u)).adjusted() - <NUM_LIT:1>) for u in units]<EOL>best = min(enumerate(exponents), key=itemgetter(<NUM_LIT:1>))[<NUM_LIT:0>]<EOL>return dict(val=round(to_unit(units[best]), round_digits),<EOL>label=units[best][<NUM_LIT:0>],<EOL>multiplier=units[best][<NUM_LIT:1>])<EOL>
Convert a value to the most reasonable unit.

    The most reasonable unit is roughly the one with the smallest exponent
    absolute value when written in scientific notation. For example
    `1.5` is more reasonable that `.0015` and `22` is more reasonable
    than `22000`. There is a bias towards numbers > 1, so `3.2` is
    considered more reasonable that `.32`.