Knowledge Base - Sorting special values

"[...] Firstly can I say that this product is superb and we are very happy with it.

The problem however has come to light as we have added more property to the site (estate agents). As we have entered property of larger value, over 1 million we have a problem. We would like to enter the value as 1,000,000 if we do this it wont sort correctly. We have had to use 1000,000 which works but doesn't look right. [...]

With thanks for all your hard work

Chris"

 

[...] The ordering plugin use mysql to make mathematical comparisons to test values. For exemple 1 < 2, 2 < 3, ...1000000 > 1. But in your case 1,000,000 is less to 2, because for the system, 1,000,000 is equals to 1.0.

Then it's very important to store the numbers in real format: 1 million = 1000000. Excatelly like you enter this value in a spreadsheet.

After that to be more easy to read for humans, you can modifiy the detailled view template to format the output of the value. You can create a custom code, or use this php function: number_format(). Exemple:

  • In sobi2 the value is stored has 1000000 (then the sort can work)
  • In the detailled view template, where the number should appears add this code:
  • echo number_format($fieldsObjects['field_price']->data,".", ",");
  • Then for a number of 1000000.99 (1million and 99 cents), the result will be 1,000,000.99

 

Applies To

All Products