Working with mysql floats

I am setting up a Word Press plugin called Gravity Forms , now the plugin uses a column as a float data type

now I have created a completely new interface for displaying the details of the post being sent, I have a set of checkboxes in the form, which Gravity Forms does , adding field_number as a float and then the value against it

now for one set of checboxes in my form, it uses field_number as 2 , now 2 remains a constant, regardless of how many flags there are and then some point values ​​are typed, for example, 2.1 for a certain value, and then 2.2 for a certain value, etc. . up to n times depending on the number of flags in the form. Please see the image below for more explanation!

enter image description here

Important Note! I can’t change the float data type as something else like vahrchar or decimal , it completely blocks the plugin

now I struggled with getting float values ​​because float is not so reliable and easy to use. I saw other blogs where people prefer double or decimal over it

my main problem was this request,

SELECT value FROM wp_rg_lead_detail WHERE lead_id=".absint( $lead['id'] )." and field_number=2.4

now this query is executed, I did not get any result, so what I did changed my query and passed the value as decimal!

SELECT value FROM wp_rg_lead_detail WHERE lead_id=".absint( $lead['id'] )." and CAST(field_number AS DECIMAL) = CAST(2 AS DECIMAL)

Now this query worked just fine and returned the number of rows, but the problem is that it lacks data and does not return all the data. for example, if I have 5 lines, as you can see, in the image above it only returns three lines and skips two lines! any help?

+4
source share
1 answer

2, , :

SELECT value 
FROM wp_rg_lead_detail 
WHERE lead_id=".absint( $lead['id'] )." 
    and truncate(field_number,0) = 2
+2

Source: https://habr.com/ru/post/1691883/


All Articles