Skip to content

How can we detect if a number is an integral value? #211

@MangelMaxime

Description

@MangelMaxime

There is currently a subtle bug in Thoth.Json (since for ever probably), where number with decimal set to 0 like 10.0 or 2120.0 are considered integral value.

This is because in JavaScript the test we use is:

function isIntegral(value) {
    return isFinite(value) && Math.floor(value) === value;
}

// Returns
isIntegral(10.0) // ❌
isIntegral(2120.0) // ❌
isIntegral(10.1) // ✅

Case marked with ❌ are incorrect because they return true instead of false.

This means that 10.0 is consider a valid number for int16, etc.

This bug is not present in Thoth.Json.Newtonsoft, neither in Thoth.Json.Python.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions