Skip to content

parse_number

relationalai.semantics.std.numbers
parse_number(
value: StringValue, precision: int = 38, scale: int = 14
) -> Expression

Parse a string value as a number with specified precision and scale.

  • value

    (StringValue) - The string value to parse.
  • precision

    (int, default: 38) - The precision (total number of digits).
  • scale

    (int, default: 14) - The scale (number of decimal places).
  • Expression - An Expression computing the parsed number. Returns Number.

Parse string to number:

>>> numbers.parse_number("123.456")
>>> numbers.parse_number(Product.price_str, precision=10, scale=2)
RelationalAI Documentation
└──  Build With RelationalAI
    └──  Understand how PyRel works > Use advanced reasoning > Rules-based reasoning
        └──  Work with numbers
            └──  Parse numeric text safely