2

I changed price rounding calculation from round to Ceil (PHP function). Its Means if price 0.0001 then it will become 1.00

Now the problem in price calculation.

Example:-
Product Price = 8249.25

5% tax = 412.4625

Total = 8661.7125

After using ceil function it's must be 8662.00, But now it's display 8663.00 price.

I changed in those files.

Magento\Directory\Model\PriceCurrency

public function format(
    $amount,
    $includeContainer = true,
    $precision = self::DEFAULT_PRECISION,
    $scope = null,
    $currency = null
) {
    return $this->getCurrency($scope, $currency)
        ->formatPrecision(ceil($amount), $precision, [], $includeContainer);
}
/**
 * Round price
 *
 * @param float $price
 * @return float
 */
public function round($price) {
    return round(ceil($price), 2);
}

Magento_Catalog/js/price-utils

function formatPrice(amount, format, isShowSign) {
    var s = '',
        precision, integerRequired, decimalSymbol, groupSymbol, groupLength, pattern, i, pad, j, re, r, am;

    format = _.extend(globalPriceFormat, format);


    precision = isNaN(format.requiredPrecision = Math.abs(format.requiredPrecision)) ? 2 : format.requiredPrecision;
    integerRequired = isNaN(format.integerRequired = Math.abs(format.integerRequired)) ? 1 : format.integerRequired;
    decimalSymbol = format.decimalSymbol === undefined ? ',' : format.decimalSymbol;
    groupSymbol = format.groupSymbol === undefined ? '.' : format.groupSymbol;
    groupLength = format.groupLength === undefined ? 3 : format.groupLength;
    pattern = format.pattern || '%s';

    if (isShowSign === undefined || isShowSign === true) {
        s = amount < 0 ? '-' : isShowSign ? '+' : '';
    } else if (isShowSign === false) {
        s = '';
    }
    pattern = pattern.indexOf('{sign}') < 0 ? s + pattern : pattern.replace('{sign}', s);

    i = parseInt(
            amount = Number(Math.round(Math.ceil(Math.abs(+amount || 0)) + 'e+' + precision) + ('e-' + precision)),
            10
        ) + '';
    pad = i.length < integerRequired ? integerRequired - i.length : 0;

    i = stringPad('0', pad) + i;

    j = i.length > groupLength ? i.length % groupLength : 0;
    re = new RegExp('(\\d{' + groupLength + '})(?=\\d)', 'g');

    am = Number(Math.round(Math.ceil(Math.abs(amount - i)) + 'e+' + precision) + ('e-' + precision));
    r = (j ? i.substr(0, j) + groupSymbol : '') +
        i.substr(j).replace(re, '$1' + groupSymbol) +
        (precision ? decimalSymbol + am.toFixed(2).replace(/-/, 0).slice(2) : '');

    return pattern.replace('%s', r).replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.