Welcome Guest, Not a member yet? Register   Sign In
Ci4 orderBy Float Value
#1

Hi All,
I have a little problem with sort values (Float type) from database mysql.
I use -> orderBy("FieldFloat","desc"), 
But incorrect result, Please helpme
Reply
#2

can you give more sample, since i have no problem with it.
Reply
#3

(This post was last modified: 08-22-2021, 08:51 PM by nfaiz.)

(08-22-2021, 07:27 AM)hieuhiti Wrote: Hi All,
I have a little problem with sort values (Float type) from database mysql.
I use -> orderBy("FieldFloat","desc"), 
But incorrect result, Please helpme

Check your datatype.

or you can try
PHP Code:
$builder->select('(FieldFloat * 1) AS FieldFloat, Field2');
$builder->orderBy('FieldFloat','desc'); 
Reply
#4

Please read this:
MySQL - B.3.4.8 Problems with Floating-Point Values

Your problem may be a MySQL problem with floats.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

Thanks for everyone's help,
I tried:
$this->orderBy('CAST(FieldFloat as DECIMAL(10,5))','DESC',FALSE);
and got the desired result.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB