Skip to content

multipleOf validation and decimals - the floating number problem ... #167

Description

Hey Geraint,

you should not use the modulo operator for validating multipleOf if validating decimals.
See e.g.
http://stackoverflow.com/questions/16909104/how-to-check-whether-an-integer-is-divisible-by-a-decimal

The JSON Schema latest spec. says multipleOf is for integer and number and
"A numeric instance is valid against "multipleOf" if the result of the division of the instance by this keyword's value is an integer."

For now tv4 / multipleOf returned false for some decimal numbers which SHOULD be true
Consider 6.6 multipleOf 2.2 ----> is invalid for tv4
while 6.6666 multipleOf 2.2222 -> is valid for tv4 !

I think this is not very straightforward.

I made a fiddle to experiment with it
http://jsfiddle.net/we1nt9ye/1/
What do you think of "Alternative 2" ?

btw:
There might be better things for bigger decimals like
https://github.com/dtrebbien/BigDecimal.js
or
https://github.com/MikeMcl/big.js/
or
https://github.com/MikeMcl/decimal.js/

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions