我想验证坐标。这些将作为real数据列存储在Postgres文档中。
实数4字节可变精度不精确6位小数位精度
我从以下几个方面开始
@IsNumber()
@Min(-90)
@Max(90)
/* precision check */
public latitude: number;
@IsNumber()
@Min(-180)
@Max(180)
/* precision check */
public longitude: number;我想知道如何检查这些浮点数的精度。它必须有6位的精度。
提前感谢
发布于 2020-04-14 18:14:48
对于所有定制的东西,比如精度,最好的方法是编写自己的自定义验证器,在那里可以使用regexp或其他方式来验证输入数据。
最简单的方法是编写一个验证器:https://github.com/typestack/class-validator#custom-validation-classes
更高级的方法是编写自己的验证装饰器:https://github.com/typestack/class-validator#custom-validation-decorators
发布于 2022-01-31 14:31:41
这个包已经为这类输入提供了验证器。
@IsLatLong()
@IsLatitude()
@IsLongitude()https://stackoverflow.com/questions/61183093
复制相似问题