Jump to content

Rounding numbers to 2 digits after comma (ps_round)


folkifoon

Recommended Posts

You can change it to php's default number_format($value, 2);

 

or modify the ceilf and floorf methods in tools.php

	public static function ceilf($value, $precision = 0)
	{
		$precision_factor = $precision == 0 ? 1 : pow(10, $precision);
		$tmp = $value * $precision_factor;
		$tmp2 = (string)$tmp;
		// If the current value has already the desired precision
		if (strpos($tmp2, '.') === false)
			return ($value);
		if ($tmp2[strlen($tmp2) - 1] == 0)
			return $value;
		return ceil($tmp) / $precision_factor;
	}
  • Like 1
Link to comment
Share on other sites

Hi Nemo,

But if i just want to change the code in the invoice.tpl, what should, what should that be?
 

<td style="text-align: centre; width: 10%; white-space: nowrap;">
{if $tax_excluded_display}
{Tools::ps_round($order_detail.unit_price_tax_excl,2)}
{else}
{Tools::ps_round($order_detail.unit_price_tax_incl,2)}
{/if}
</td>
Link to comment
Share on other sites

  • 4 months later...
×
×
  • Create New...