When typecasting form data to integer for sorting, data loss that doesn't fit the type cast into should be dropped. (This is how type casting works in any major programming language and how it is SUPPOSED to work.)
When a field typecast to integer that contains "6", "4", "0.5" and "3 lbs.", the data should be first truncated to "6", "4", "0", and "3", then ordered to "0", "3", "4", "6".
Currently it orders them: "4", "6", "0.5", and "3 lbs." (And the "0.5" and "3 lbs." don't seem to be in any strict order, they just get shoved to the end using some other predetermined sort order.) I ran into this problem here: [http://kmarchipelago.wikidot.com/forge:weapons/order/_weight::integer/]
In my situation, the non-numeric text is an artifact I'm working on removing, but the problem of not properly type casting floating point numbers to integers still remains.
This casting is made by postgres database engine, only integer like strings ( ^-?[0-9]+$ ) are casted to numeric type and sorted, any other are treated as null while type casting is used. So "0.5" and "3 lbs." are null's.
Bartłomiej Bąkowski @ Wikidot Inc.
';.;' TeRq (Write PM)
So now that the problem in the process has been identified… all that remains is for it to be fixed! So that it actually type casts. Not behaving like most major programming languages is a flaw in design. C/C++/C#, Java, PHP, etc. all can properly truncate strings when type casting, and there's no good reason why that behavior isn't identical here.
Hi Morvandium,
Since TeRq said that they are using the Postgres database engine to handle the casting, they are somewhat at the mercy of how the database engine handles the cast.
Not sure how likely this will be fixed, but for the moment it hasn't been rejected so it's possible.
I would recommend making the changes on your site end for an immediate fix - i.e. change the underlying values so that they sort as you require them to be sorted.
If you require additional help with this, please feel free to contact us on the Wikidot Community.
~ Leiger - Wikidot Community Admin - Volunteer
Wikidot: Official Documentation | Wikidot Discord server