Skip to content

v.multipleOf does not handle some non-integer inputs wellΒ #1375

@esdmr

Description

@esdmr

It seems that v.multipleOf tries to find the remainder of the input divided by the requirement. This might not yield an appropriate result if their division has floating point precision errors:

const Length = v.pipe(v.number(), v.multipleOf(0.01), v.description('in meters, with centimeter precision'));

toJsonSchema(Length) // {"type": "number", "multipleOf": 0.01, "description": ...}

v.parse(Length, 3); // Invalid multiple: Expected %0.01 but received 3

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions