processwire / processwire-issues

ProcessWire issue reports.
44 stars 2 forks source link

float field is rounded when rounding is disabled #1949

Open hiboudev opened 3 months ago

hiboudev commented 3 months ago

Field should not be rounded: image

I set a value via code or admin: 2387.04123456 and value recorded in database is: 2387.04

ryancramerdesign commented 3 months ago

@hiboudev I can't duplicate that here. The value 2387.04123456 saves correctly and remains here. Are you using a FieldtypeFloat field (what I'm using), or using the InputfieldFloat with some other field type?

hiboudev commented 3 months ago

@ryancramerdesign I did another test, inserting directly in database and I see the same rounding, and here is the solution: https://stackoverflow.com/a/62515384 If I set the type double to this field, it saves correctly the decimal value. My database was created by ProcessWire, so why do we have a difference? Because I'm using InnoDB? What is the type in your database? This is the configurations PW created:

image

image

matjazpotocnik commented 2 months ago

@ryancramerdesign, I can confirm what @hiboudev is experiencing - the value is truncated. My table/fields uses MyISAM engine and utf8_general_ci Collation. As soon I change the data type to double, the value is shown as it should, not truncated.

hiboudev commented 2 months ago

@ryancramerdesign In FieldtypeFloat, this 'float NOT NULL' should be a 'double NOT NULL'.

public function getDatabaseSchema(Field $field) {
  $schema = parent::getDatabaseSchema($field); 
  $schema['data'] = 'float NOT NULL';
  return $schema;
}
matjazpotocnik commented 1 month ago

@hiboudev, this issue should be fixed in https://github.com/processwire/processwire/commit/6e93844c19387e137b4900fab8b990a898f963bc (PW 3.0.241). Can you confirm?