[SOLVED]Format string calc element

SymOn75

Member
Hi,
Fabrik is fantastic and allows me to develop many applications.
I've a problem with format string in calc element (J2.5 and Fabrik 3.0.x)
My calc element is as follows:
Calculation: return '{tablename___elementA'} + '{tablename___elementB'};
Format string: ? %01.2f
It work fine but when there's a number with thousands it show (for example) 1235.66 but I need a thousand separation (space or comma it's ok for me).
How I can obtain this results?
 
You can't direct use at Format string for the thousand separator. Just change your code to :

PHP:
$elementa = '{tablename___elementA}';
$elementb = '{tablename___elementB}';
$result = $elementa + $elementb;
return number_format($result, 0, ".", ",");

Note : Change the number format above appropriate with your criteria.
 
Thanks myfatebiz for your help but it doesn't work :(
When in calculation area I put your code the results is as follow:
- if in elementA (or B) I insert a number with thousands like (for example) 1000 it shows in results "1"!!!!

I need in result calc element a number with thousands separator...
I can not believe that it is impossible....:(
 
Try test simple like this see the result..

PHP:
$result = '10000';
return number_format($result, 0, ".", ",");

It will return to me the result like 10,000
 
You might can try different situation as like below :

PHP:
$elementa = (int)'{tablename___elementA}';
$elementb = (int)'{tablename___elementB}';
$result = $elementa + $elementb;
return number_format($result, 0, ".", ",");

OR

PHP:
$elementa = (int)'{tablename___elementA_raw}';
$elementb = (int)'{tablename___elementB_raw}';
$result = $elementa + $elementb;
return number_format($result, 0, ".", ",");

OR

PHP:
$elementa = '{tablename___elementA_raw}';
$elementb = '{tablename___elementB_raw}';
$result = $elementa + $elementb;
return number_format($result, 0, ".", ",");
 
It works!!! Great!
Now there's a last problem: why the sum column in calc element it's wrong???
See the attachment picture
2014-07-30_11h22_33.png
 
I think you need create 2 calc element which is calc 1 have thousand separator and calc 2 do not have thousand separator to show at listing with sum all value at column calc 2.

Conclusion is :

Calc 1 :
- Show at form view but hidden at listing

Calc 2 :
- Hidden at form view but show at listing with sum all calculation on this column.
 
If I've understood correctly in form view calc 1 show result with thousand separator, and calc 2 show in list, for each row, result without thousand separator and sum of column without thousand separator?
I think this doesn't solve my problem.
I need to show in list view cal element and sum of column with thousand separator.
In form view I don't need to show calc element and his results...
Myfatebiz, may be that I've doesn't understood your example.
Please, can you explain it me another time?
Thanks very much for your help
 
I just do some research and found a solution for your problem. It took a few hour for that because there is no tutorial on internet.

Step one : Calculation_Element_1
- Using your working code for Calculation Element 1 which is using number_format.
- Under Calculations tabs put this code FORMAT(SUM(%s),2) under Custom Calc at Custom query area. Please see the attachment.
- Your can show this Calculation_Element_1 on listing.

Step two : Calculation_Element_2
- Using my code below to update and remove the comma at column Calculation_Element_1 after save. This is important because it will working for sum all row.
PHP:
$db = JFactory::getDBO();
$db->setQuery("UPDATE `your_table` SET `Calculation_Element_1` = REPLACE(`Calculation_Element_1`, ',', '') WHERE `id` = '{your_table___id}'");
return $db->loadResult();
- Your can hide this Calculation_Element_2 on listing.

Remark : I have test this by my self and it working. I hope you understand what i say.
 

Attachments

  • Calculation Element 1.png
    Calculation Element 1.png
    163 KB · Views: 811
  • Calculation Element Listing.png
    Calculation Element Listing.png
    464.9 KB · Views: 776
  • Calculation Element PHPMyAdmin.png
    Calculation Element PHPMyAdmin.png
    223.9 KB · Views: 794
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top