Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed PR #192 (multipleOf decimal with big integer value) #193

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ var unique = function(array, len) {

var isMultipleOf = function(name, multipleOf) {
var res;
var factor = ((multipleOf | 0) !== multipleOf) ? Math.pow(10, multipleOf.toString().split('.').pop().length) : 1
var factor = Number.isInteger(multipleOf) ? 1 : Math.pow(10, multipleOf.toString().split('.').pop().length)
if (factor > 1) {
var factorName = ((name | 0) !== name) ? Math.pow(10, name.toString().split('.').pop().length) : 1
var factorName = Number.isInteger(name) ? 1 : Math.pow(10, name.toString().split('.').pop().length)
if (factorName > factor) res = true
else res = Math.round(factor * name) % (factor * multipleOf)
}
Expand Down
21 changes: 21 additions & 0 deletions test/json-schema-draft4/multipleOf.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,26 @@
"valid": false
}
]
},
{
"description": "by big number",
"schema": {"multipleOf": 0.01},
"tests": [
{
"description": "1658529657949 is multiple of 0.01",
"data": 1658529657949,
"valid": true
},
{
"description": "1658529657949.05 is multiple of 0.01",
"data": 1658529657949.05,
"valid": true
},
{
"description": "1658529657949.055 is not multiple of 0.01",
"data": 1658529657949.055,
"valid": false
}
]
}
]