Skip to content

Commit 56417c4

Browse files
committed
fix: catch multiple of issue for decimals
1 parent 10347c4 commit 56417c4

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

lob_python/model_utils.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -914,16 +914,22 @@ def check_validations(
914914
current_validations = validations[input_variable_path]
915915
if (is_json_validation_enabled('multipleOf', configuration) and
916916
'multiple_of' in current_validations and
917-
isinstance(input_values, (int, float)) and
918-
not (float(input_values) / current_validations['multiple_of']).is_integer()):
919-
# Note 'multipleOf' will be as good as the floating point arithmetic.
920-
raise ApiValueError(
921-
"Invalid value for `%s`, value must be a multiple of "
922-
"`%s`" % (
923-
input_variable_path[0],
924-
current_validations['multiple_of']
925-
)
926-
)
917+
isinstance(input_values, (int, float))):
918+
# since floating point arithmetic can be imprecise, we'll convert input_values to string
919+
# and determine whether the decimal place is in a value position (within 3 spots of the end of the string)
920+
try:
921+
decimal_index = str(input_values).index('.')
922+
if decimal_index < len(str(input_values)) - 3:
923+
raise ApiValueError(
924+
"Invalid value for `%s`, value must be a multiple of "
925+
"`%s`" % (
926+
input_variable_path[0],
927+
current_validations['multiple_of']
928+
)
929+
)
930+
except:
931+
# if no decimal, then it's a multiple of 0.01
932+
print("whole dollar amount")
927933

928934
if (is_json_validation_enabled('maxLength', configuration) and
929935
'max_length' in current_validations and

0 commit comments

Comments
 (0)