Custom field with format currency

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
philmills
User
Posts: 535

Custom field with format currency

Post 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 ?


mobhar
User
Posts: 11660

Post by mobhar »

You may simply use PHP number_format() function to customize the value in Row_Rendered server event.


arbei
User
Posts: 9288

Post 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 = "")

philmills
User
Posts: 535

Post by philmills »

Thanks so much!
Got it working with this:

$this->TotalCost->ViewValue = FormatCurrency($totalcost, $this->TotalCost->formatPattern());


Post Reply