Steps to repeat:
1. Enable Number module.
2. Create a new content type with a Float field type.
3. Create a new node using a value like '123.' or '9.' (w/o quotes) for the Float field type.

Expected Results:
Print an error message for invalid value. An alternative would be remove the decimal point (save '123' or '9' in the given examples).

Actual Results:
PDOException: SQLSTATE[01000]: Warning: 1265 Data truncated for column 'field_number_value' at row 1: INSERT INTO {field_data_field_number} (entity_type, entity_id, revision_id, bundle, delta, language, field_number_value) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6); Array ( [:db_insert_placeholder_0] => node [:db_insert_placeholder_1] => 199 [:db_insert_placeholder_2] => 199 [:db_insert_placeholder_3] => teste [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => 1. ) in field_sql_storage_field_storage_write() (line 451 of /path/to/drupal/modules/field/modules/field_sql_storage/field_sql_storage.module).


generalredneck’s picture

Status: Active » Needs review
683 bytes
PASSED: [[SimpleTest]]: [MySQL] 40,348 pass(es). View

I got this one...

Turns out that if we were using Decimal fields... this would work... however floats are a special case since we can't "round" them. What I ended up doing was converting the variable to a floatval. This should take care of all cases with no side-effects AFAIK.

xatiu’s picture

Issue summary: View changes

I 've issued the same problem, and the patch solved it. Could we merge this to core (number module)?
Thank you

generalredneck’s picture

If the patch still applies up the version and mark as reviewed and tested by the community. We will see if someone comes around and commits it.

Patil_kunal27’s picture

For the approach of remove the decimal point, you can use

$items[$delta]['value'] = floatval($item['value']);
$items[$delta]['value'] = (float)$item['value'];
$items[$delta]['value'] = number_format($item['value'],2);

mirsoft’s picture

Version: 7.22 » 7.50
Status: Needs review » Reviewed & tested by the community

The issue was identified and reproduced on several D7 systems on the latest Drupal 7 version to date. Confirmed the patch #1 fixed the issue.
Drupal 8 is not affected.

mirsoft’s picture

Side note: It also seems that the error behaves differently on different MySQL server settings. On one installation the exception was thrown only if "." character was inserted. On different installation, also insertions like "55." failed.

Fabianx’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Drupal bugfix target, +Needs tests

As this is a bug, we will need tests to check for this new case to ensure it does not regress again.

aerozeppelin’s picture

Tests to check for PDO errors, when saving a node having a field of type 'Float'.

The last submitted patch, 8: test-only-fail-2042411-8.patch, failed testing.

Fabianx’s picture

Version: 7.5 » 7.x-dev