I have a precision problem storing a float value in mysql via jpa (EclipseLink). In my code I have annotated the field with
@Column(precision=15, scale=7)
private float x;
But when i store a value like 322,249878 the database returns 322.25. Whats going on there :)?
precisionandscalesettings are only applicable to exact numeric types (i.e.BigDecimalin Java anddecimalin MySQL).Floating point types (
floatanddouble) are approximate by their nature, therefore these settings don’t make sense for them.Also note that if you change type of this field to
BigDecimalyou should initialize it with precise values as well.