processwire-issues icon indicating copy to clipboard operation
processwire-issues copied to clipboard

float field is rounded when rounding is disabled

Open hiboudev opened this issue 1 year ago • 5 comments

Field should not be rounded: image

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

  • ProcessWire version: 3.0.240
  • (Optional) PHP version:
  • (Optional) MySQL version:
  • (Optional) Any 3rd party modules that are installed and could be related to the issue:

hiboudev avatar Jul 04 '24 13:07 hiboudev

@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?

ryancramerdesign avatar Jul 05 '24 14:07 ryancramerdesign

@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

hiboudev avatar Jul 06 '24 16:07 hiboudev

@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.

matjazpotocnik avatar Jul 20 '24 07:07 matjazpotocnik

@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;
}

hiboudev avatar Aug 02 '24 15:08 hiboudev

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

matjazpotocnik avatar Aug 10 '24 18:08 matjazpotocnik

@hiboudev I'm closing this issue; reopen it if Ryan's fix isn't working for you.

matjazpotocnik avatar Dec 14 '24 12:12 matjazpotocnik