@@ -171,6 +171,7 @@ def __init__( # noqa: PLR0913, PLR0917
171171 use_generic_container_types : bool = False , # noqa: FBT001, FBT002
172172 strict_types : Sequence [StrictTypes ] | None = None ,
173173 use_non_positive_negative_number_constrained_types : bool = False , # noqa: FBT001, FBT002
174+ use_decimal_for_multiple_of : bool = False , # noqa: FBT001, FBT002
174175 use_union_operator : bool = False , # noqa: FBT001, FBT002
175176 use_pendulum : bool = False , # noqa: FBT001, FBT002
176177 target_datetime_class : DatetimeClassType | None = None ,
@@ -184,6 +185,7 @@ def __init__( # noqa: PLR0913, PLR0917
184185 use_generic_container_types ,
185186 strict_types ,
186187 use_non_positive_negative_number_constrained_types ,
188+ use_decimal_for_multiple_of ,
187189 use_union_operator ,
188190 use_pendulum ,
189191 target_datetime_class ,
@@ -268,6 +270,12 @@ def get_data_float_type( # noqa: PLR0911
268270 data_type_kwargs = self .transform_kwargs (kwargs , number_kwargs )
269271 strict = StrictTypes .float in self .strict_types
270272 if data_type_kwargs :
273+ # Use Decimal instead of float when multipleOf is present to avoid floating-point precision issues
274+ if self .use_decimal_for_multiple_of and "multiple_of" in data_type_kwargs :
275+ return self .data_type .from_import (
276+ IMPORT_CONDECIMAL ,
277+ kwargs = {k : Decimal (str (v )) for k , v in data_type_kwargs .items ()},
278+ )
271279 if not strict :
272280 if data_type_kwargs == {"gt" : 0 }:
273281 return self .data_type .from_import (IMPORT_POSITIVE_FLOAT )
0 commit comments