from .math_basis_points_convert_rate import convert_rate from .math_basis_points_types import RateUnit _MAX_SAFE = 9007199254740991 def to_basis_points(value: str, unit: RateUnit) -> int: """A rate as whole basis points, the unit the registry keeps rates in. Refuses a rate that is not a whole number of basis points (12.345% is 1234.5) rather than round it: which way to round a rate is the caller's policy, not a conversion's. """ text = convert_rate(value, unit, "basis-points") if "." in text: raise ValueError("%s %s is not a whole number of basis points" % (value, unit)) bp = int(text) if bp > _MAX_SAFE or bp < -_MAX_SAFE: raise ValueError("%s %s is too large for integer basis points" % (value, unit)) return bp