Schema - Float (Number)
The .float
method is used to validate whether a given value is a floating-point number. It ensures that the input is a valid decimal number, differentiating it from integers, and can be further combined with additional validation methods to define specific rules for numeric inputs.
This method is particularly useful for validating data like prices, measurements, or any values that require decimal precision.
Example
Below is an example of how to use .float
to validate whether a value is a valid floating-point number:
import { schema } from "vkrun"
const exampleSchema = schema().number().float()
const validateA = exampleSchema.validate(123.5) // Valid float
const validateB = exampleSchema.validate(123) // Invalid float (integer)
console.log(validateA) // true
console.log(validateB) // false