public static function formatToPrice($value, $currency = null)
    {
        $decimals = 2;
        $currencyDecimals = array('JPY' => 0, 'TWD' => 0);
        if ($currency && array_key_exists($currency, $currencyDecimals)) {
            if (strpos($value, ".") !== false && (floor($value) != $value)) {
                //throw exception if it has decimal values for JPY and TWD which does not ends with .00
                throw new \InvalidArgumentException("value cannot have decimals for $currency currency");
            }
            $decimals = $currencyDecimals[$currency];
        } elseif (strpos($value, ".") === false) {
            // Check if value has decimal values. If not no need to assign 2 decimals with .00 at the end
            $decimals = 0;
        }
        return self::formatToDecimal($value, $decimals);
    }
public static function formatToPrice($value, $currency = null)
    {
        $decimals = 2;
        $currencyDecimals = array('JPY' => 0, 'TWD' => 0);
        if ($currency && array_key_exists($currency, $currencyDecimals)) {
            if (strpos($value, ".") !== false && (floor($value) != $value)) {
                //throw exception if it has decimal values for JPY and TWD which does not ends with .00
                throw new \InvalidArgumentException("value cannot have decimals for $currency currency");
            }
            $decimals = $currencyDecimals[$currency];
        } elseif (strpos($value, ".") === false) {
            // Check if value has decimal values. If not no need to assign 2 decimals with .00 at the end
            $decimals = 0;
        }
        return self::formatToDecimal($value, $decimals);
    }
public static function formatToPrice ( $ value , $ currency = null ) { $ decimals = 2 ; $ currencyDecimals = array ( 'JPY' => 0 , 'TWD' => 0 ) ; if ( $ currency && array_key_exists ( $ currency , $ currencyDecimals ) ) { if ( strpos ( $ value , "." ) !== false && ( floor ( $ value ) != $ value ) ) { //throw exception if it has decimal values for JPY and TWD which does not ends with .00 throw new \ InvalidArgumentException ( "value cannot have decimals for $currency currency" ) ; } $ decimals = $ currencyDecimals [ $ currency ] ; } elseif ( strpos ( $ value , "." ) === false ) { // Check if value has decimal values. If not no need to assign 2 decimals with .00 at the end $ decimals = 0 ; } return self :: formatToDecimal ( $ value , $ decimals ) ; }
Helper method to format price values with associated currency information.

It covers the cases where certain currencies does not accept decimal values. We will be adding
any specific currency level rules as required here.

@param      $value
@param null $currency
@return null|string
Helper method to format price values with associated currency information .