Jump to content
Michael Pusch

How to add currency format

Recommended Posts

Just playing with the banner field and php bases formating and have a little question.

$price = $CustomFields->fieldValue('jr_price',$entry);
$volume = $CustomFields->fieldValue('jr_volume',$entry);
$total = $price * $volume;
return $total;

How can I put in the currency format like this:

1200,- €

instead of


And additional:

How can I devide? In this way?

$total = $price / $volume;


Edited by Michael Pusch

Share this post

Link to post

I solved the devide problem with the slash. Seems to be logical.

Another problem for me is to cut the price without decimals.

I.E. not 2014,145678,- $

Better: 2014,- $

Share this post

Link to post

You need to use the php number_format function. So something like this:

return number_format($total,0).',-$';

Keep in mind that will include a thousands separator and show 1,200 instead of 1200. You can also change that to 1.200 if you add 3rd and 4th parameters to the function telling it which characters you prefer using for the thousands and decimal separators. If you just want to remove the decimal part, then you can try:

return (int) $total.',-$';


Share this post

Link to post

That works perfect for me. Thank you.

A little additional question and I know it is out of regular support - But I will try it. 😉

If I have a checkbox field with two options. I.E. Yes and No.

Is it possible to give this field intern a decimal value to calculate another thing?

Example: Yes = 0  and No = 150

I'm reading the manual up and down and use than the try and error method. At the moment without success.

Share this post

Link to post

Sure, just get the selected value first into a variable and then convert it with some simple logic

$cb = $CustomFields->fieldValue('jr_checkbox',$entry);

$cb = $cb == 'yes' ? 0 : 150;

You only have to be careful to compare against the right text. So "yes" vs. "YES" or whatever value you assigned to the "Yes" option.

Share this post

Link to post


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Please refer to our Privacy Policy.