The validator of the text-area widget for FLOAT fields rejects numbers in scientific notations (such as 1.23456E-13).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nickbn’s picture

Anybody working on this? Kind of a big deal for me.... I have a content type with a float text field and whenever I edit nodes the numbers are converted to scientific notation on the edit form then won't validate. So I have to re-enter all of the numbers in standard notation before I submit the form. Does that make sense? I'm not sure why the numbers come up in scientific notation when I edit nodes, they just do.

Thanks!

nickbn’s picture

Version: 6.x-2.0-beta » 6.x-2.6
Nikit’s picture

I change manually FLOAT to DOUBLE via MySql, and numbers became as it is...

grasmash’s picture

Thanks for that tip. Switching to double fixed it.

However, it seems like one should be able to store numbers over 1,000,000 without having it auto-convert to scientific notation and break the validator. What would be the best choice for field type when using numbers over 1 million that require decimals?. I'm using a field for Real Estate price, so I need to use large numbers with decimals, but neither float nor integer are good choices with their default settings.

Just curious. Thanks!

rfarm’s picture

having the same difficulties with this field with numbers over 999,999 but have no clue how to change from FLOAT to DOUBLE even after some searching
Can someone give some quick instructions for doing this hopefully within phpmyadmin?
Many thanks!

kbk’s picture

Version: 6.x-2.6 » 6.x-2.x-dev

Nearly 3 years later and problem still exists. To change to double in phpmyadmin:

1) Find and navigate to the table where your field is stored. The table is probably content_type_[your_content_type] if your float field allows only 1 value or content_field_[your_field_name] if it allows for many values (i.e., Add another).
2) Click on Structure for your table. Then click the checkbox next to your float field and click the pencil icon to edit it.
3) Change Type from Float to Double and Save.

If you're new enough that you require these instructions, try this on a development website/database first!

OsamaBinLogin’s picture

Yeah, this is a big deal. Can't even type in 3E8?

Single floats (32 bits, 7.2 decimal place precision, +-38 exponent) are sortof a relic of the 60s and 70s when an extra four bytes was a big deal, and floating point calculations were often done in software. You can still use it usually for screen graphics where 4 digits (1/10,000) is often enough. If you're up to $1 million, you will be losing pennies and dimes.

Everybody's moved on to double floats (64 bits, 16 decimal place precision, +-308 exponent). You can write the US national debt to the last penny. When C came out in 1980, they only supported doubles, not single floats. When the Macintosh came out in '84, all floating arithmetic was in 80 bit floats, in software, even if the original numbers were short floats. All JavaScript numbers are double floats, even the integers. Calculations with these floats are blindingly fast - even transcendential functions like log() and tan() - cuz every cpu chip does them in hardware.

So you can probably just switch to doubles and leave single floats behind and nobody'll complain. If someone does, they can go into mysql and switch the doubles to singles.

pdrake’s picture

Priority: Normal » Major
Status: Active » Needs review
FileSize
1.62 KB

Here's a patch to convert number_float storage from float to double. I'm changing the priority to major as the bug involves potential data loss for those unaware that the existing storage mechanism is single float.

Jaza’s picture

FYI, this same issue exists with Drupal 7 core FAPI float fields:
#1458852: Float number field changes up to million value to 1.--e+06 while trying to edit a node