sympy_converter.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:bce 作者: bce-toolkit 项目源码 文件源码
def convert_float_string_to_rational(symbol):
    """Convert a string that contains a float number to SymPy's internal Rational type.

    :type symbol: str
    :param symbol: The string.
    :return: Converted value.
    """

    #  Find the position of decimal dot.
    dot_pos = symbol.find(".")
    if dot_pos < 0:
        raise ValueError("Missing decimal dot.")

    #  Get the value of its numerator and denominator.
    numerator = int(symbol[:dot_pos] + symbol[dot_pos + 1:])
    denominator = 10 ** (len(symbol) - 1 - dot_pos)

    return _sympy.Rational(numerator, denominator)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号