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)
评论列表
文章目录