首页 > 解决方案 > 使用浮点数创建 Joi Schema

问题描述

因为,float() 已从 Joi 中删除,我应该使用什么来传递带点的十进制值?
我正在创建一个接收燃料值的 api,默认为“0.00”。
仅使用 number() 无效。
使用 number().precision(2) 也是无效的。

代码:

const schema = Joi.object({
price: Joi.number().precision(2).required()})

发布请求:

{
"price": 7.60
}

输出:

{
    "message": "\"price\" must be an integer",
    "stack": "ValidationError: \"price\" must be an integer"
}

标签: node.jsexpressjoimonk

解决方案


推荐阅读