whereFloat() / orWhereFloat()
Type-safe WHERE condition for float and decimal values.
Signature
whereFloat(string $column, mixed $value, string $operator = '='): self
orWhereFloat(string $column, mixed $value, string $operator = '='): self
Basic usage
Use whereFloat() for columns that hold decimal values like prices,
scores, weights or percentages. It accepts integers, floats and numeric strings –
anything that can be safely interpreted as a float.
// Step by step
$db->whereFloat('price', 19.99);
$products = $db->get('products');
// Fluent
$products = $db->whereFloat('price', 19.99)->get('products');
// → SELECT * FROM products WHERE price = 19.99
With operators
// Step by step
$db->whereFloat('price', 10.00, '>=');
$db->whereFloat('price', 99.99, '<=');
$products = $db->get('products');
// Fluent
$products = $db->whereFloat('price', 10.00, '>=')
->whereFloat('price', 99.99, '<=')
->get('products');
// → SELECT * FROM products WHERE price >= 10 AND price <= 99.99
Using orWhereFloat()
// Step by step
$db->whereFloat('discount', 0.10);
$db->orWhereFloat('discount', 0.20);
$rows = $db->get('products');
// Fluent
$rows = $db->whereFloat('discount', 0.10)
->orWhereFloat('discount', 0.20)
->get('products');
// → SELECT * FROM products WHERE discount = 0.1 OR discount = 0.2
Numeric strings
Numeric strings are accepted – useful when values come from form input or CSV files. Both dot and comma decimal separators are normalized automatically:
// All of these are valid
$db->whereFloat('price', '19.99');
$db->whereFloat('price', '19,99'); // comma separator → normalized to 19.99
$db->whereFloat('price', 20); // integer → cast to float
// → all produce: WHERE price = 19.99 or WHERE price = 20
Validation & error handling
Non-numeric values throw an InvalidArgumentException and reset the query state.
try {
$db->whereFloat('price', 'cheap'); // ❌ not a valid float
$products = $db->get('products');
} catch (\InvalidArgumentException $e) {
echo $e->getMessage();
// → Invalid float value for column 'price'.
}
See also
- whereInt() – type-safe integer filtering
- whereString() – type-safe string filtering
- where() – generic WHERE without type enforcement