def _to_mumps_number(v):
    """Given a value, attempt to coerce it to either an integer or float."""
    sign = 1
    ndec = 0
    try:
        tmp = float(v)

        if tmp.is_integer():
            return int(tmp)
        else:
            return tmp
    except ValueError:
        v = str(v)
        n = []

        # Build a number based on the MUMPS numeric conversion rules
        for c in v:
            # Look for numeric characters (digits, decimal, or sign)
            if c.isnumeric() or c in ('.', '+', '-'):
                # Make sure we only add one decimal
                if c == '.':
                    if ndec >= 1:
                        break
                    else:
                        ndec += 1

                # Correctly swap the sign
                if c == '-':
                    sign *= -1
                    continue

                # Ignore the plus signs
                if c == '+':
                    continue

                # If we made it this far, this is a valid numeric character
                n.append(c)
            else:
                # If we don't find any,
                break

        # Re-assemble the digits and attempt to convert it
        n = float("".join(n)) * sign
        return n if not n.is_integer() else int(n)