i have a domain class that contains two fields : minscale
, and maxscale
:
class TeamRuleAverageStatic extends TeamRule {
Float minscale;
Float maxscale;
}
*
i persist a record in database with minscale=0.5
and maxscale=0.9
And when i tried to query it , i don't get anything :
TeamRuleAverageStatic.findByMinscaleAndMaxscale(new Float(0.5),new Float(0.9));
I make another attempt , but without embedding maxscale :
TeamRuleAverageStatic.findByMinscale(new Float(0.5));
So i get the expected result .
i try also :
TeamRule.executeQuery('from TeamRule cu where cu.maxscale = ? and cu.minscale= ?', [new Float(0.9),new Float(0.5)])
// As TeamRule is the class mother of TeamRuleAverageStatic
Issue persists yet .
it seems that MAXSCALE
is a keyword or fields that start with the prefix 'max' , because query by the MINSCALE
field works perfectly
UPDATE:
i do best practices with SQL query manually using phphmyadmin
as GUI,
i get the same problem .
When i change the type of field to Double
it works ! WEIRD
Reallly, it is the strange IT issue that meets me .
What is the problem with FLOAT
type ?
Your issue is cause by the nature of representation float
and double
values.
Both are used to represent floating point numbers, where float
is for single-precision and double
is for double-precision numbers.
MySQL uses four bytes for single-precision values and eight bytes for double-precision values.
As from the MySql manual:
Because floating-point values are approximate and not stored as exact values, attempts to treat them as exact in comparisons may lead to problems.
You could try to use decimal
instead of float
or double
because decimal
is represented as strings internally to guarantee an exact precision.