import six
import re


def to_bytes(value):
    """Convert numbers with a byte suffix to bytes.
    """
    if isinstance(value, six.string_types):
        pattern = re.compile('^(\d+)([K,M,G]{1})$')
        match = pattern.match(value)
        if match:
            value = match.group(1)
            suffix = match.group(2)
            factor = {
                'K': 1024,
                'M': 1024 ** 2,
                'G': 1024 ** 3,
            }[suffix]

            return int(round(factor * float(value)))

    return value