Skip to content

Number validation fails on some strings with E-notation #2542

@twoRoger

Description

@twoRoger

Support plan

  • is this issue currently blocking your project? (yes/no): no
  • is this issue affecting a production system? (yes/no): yes

Context

  • node version: 14.15.4
  • module version with issue: 17.3.0
  • last module version without issue:
  • environment (e.g. node, browser, native): node
  • used with (e.g. hapi application, another framework, standalone, ...): standalone
  • any other relevant information:

What are you trying to achieve or the steps to reproduce?

var joi = require("joi")
const schema = joi.number();
schema.validate('1.9642346977926366E-5'); // => 0.000019642346977926367
schema.validate('1.9642346977926364E-5'); // => ValidationError

https://runkit.com/tworoger/60094327f1b8ed001a128f13

What was the result you got?

{error: exports.ValidationError: "value" must be a safe number, value: 0.000019642346977926364}

What result did you expect?

{value: 0.000019642346977926364}

Metadata

Metadata

Assignees

Labels

bugBug or defect

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions