const schema = Joi.number().precision(4).min(0).max(1)
schema.validate(0.9999)
// { error: null, value: 0.9999 }
schema.validate(0.9999999)
// { error: null, value: 1 }
schema.validate(3)
// { error:
// { [ValidationError: "value" must be less than or equal to 1]
// isJoi: true,
// name: 'ValidationError',
// details: [ [Object] ],
// _object: 3,
// annotate: [Function] },
// value: 3 }
I expected schema.validate(0.9999999) to return an error, not to change my value to 1
Indeed that's a lack in documentation, you need strict mode (or convert: false) to disable that behavior.
Joi.number().precision(4).strict().min(0).max(1) does the job. thank you
Most helpful comment
Joi.number().precision(4).strict().min(0).max(1)does the job. thank you