Skip to content

multipleOf fails validation (decimals) #247

Closed
@harmv

Description

@harmv

I noticed that json schemas with multipleOf fail to validate when using decimals.

1.1 is accepted as multiple of 0.1, but 1.9 is not.

example program that demonstrates the problem

    from jsonschema import validate, __version__
    import json

    schema = json.loads("""
    {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "type": "object",
        "properties": {
            "foo": {
                "type": "number",
                "multipleOf" : 0.1
            }
        },
        "additionalProperties": false,
        "required": [
            "foo"
        ]
    }
    """)

    example1 = json.loads("""
    { "foo": 1.1}
    """)

    example2 = json.loads("""
    { "foo": 1.9}
    """)


    def main():
        print "jsonschema.__version__ = ", __version__
        validate(example1, schema)  # this one works
        validate(example2, schema)  # this should work, but doesn't

    if __name__ == "__main__":
        main()

result

jsonschema.exceptions.ValidationError: 1.9 is not a multiple of 0.1

expected result

validation passes

version

jsonschema.__version__ =  2.5.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions