node.js - 使用浮点数创建 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"
}
解决方案
推荐阅读
- c# - 在非控制器类中返回 RedirectToRouteResult
- javascript - 在动态页面中页面加载后显示/隐藏元素
- git - 用于检查具有潜在上游更改的最新版本分支的 Git 脚本
- javascript - 如何调整 D3 轮廓的大小
- python - 您可以使用元素 ID 来检查元素是否可点击
- google-sheets - Google Sheets MATCH 字符串并向右返回 OFFSET 2 列
- mongodb - rs.initiate() 为副本集设置 docker-compose 时出现问题
- docker - Confluence docker:找不到指定的 Dockerfile
- webview2 - WebView2 控件不在工具箱中
- autohotkey - 如果 WinExist 使用变量和 RegEx