Page 1 of 1
Custom field with format currency
Posted: Wed Sep 28, 2022 11:37 pm
by philmills
I have a custom field TotalCost using cast('' as signed)
In Row_Rendered I'm populating TotalCost by counting the items in an adjacent field, then multiplying that by another field's value.
I need TotalCost to display in currency format, so i set the field's Format attribute to Currency.
If I use this in Row_Rendered:
$this->TotalCost->CurrentValue=$totalcost;
the field correctly displays as a currency field but $totalcost isn't calculated, so it always shows as €0,00
If I use this in Row_Rendered:
$this->TotalCost->ViewValue=$totalcost;
the calculation is correct but it's displayed as a whole number not as currency.
How can I force TotalCost to show as currency when using ViewValue ?
Re: Custom field with format currency
Posted: Thu Sep 29, 2022 10:13 am
by mobhar
You may simply use PHP number_format() function to customize the value in Row_Rendered server event.
Re: Custom field with format currency
Posted: Thu Sep 29, 2022 10:17 am
by arbei
You may use the PHPMaker's FormatCurrency()
. From the source:
/**
* Format currency
*
* @param float $value Value
* @param string $pattern Formatter pattern
* @return string
*/
function FormatCurrency($value, $pattern = "")
Re: Custom field with format currency
Posted: Thu Sep 29, 2022 1:57 pm
by philmills
Thanks so much!
Got it working with this:
$this->TotalCost->ViewValue = FormatCurrency($totalcost, $this->TotalCost->formatPattern());