Specialprice & finalprice returns no decimals Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Tierprice decimals displayRemove decimals from configurable option price update scriptFormatting finalPriceRemove price decimals on list and product viewRemove decimals list & product viewi want to write custom sql query to select low and high price in magento2?Prices Zero on listing pages after update to Magento 1.9getFinalPrice returns 0.00 for some configurable productsAfter Plugin does not run at checkoutMagento 2 remove currency symbol and decimals when price is .00
What is this building called? (It was built in 2002)
On SQL Server, is it possible to restrict certain users from using certain functions, operators or statements?
Is safe to use va_start macro with this as parameter?
Wu formula for manifolds with boundary
Why are both D and D# fitting into my E minor key?
For a new assistant professor in CS, how to build/manage a publication pipeline
Why wasn't DOSKEY integrated with COMMAND.COM?
Dating a Former Employee
Is it a good idea to use CNN to classify 1D signal?
Can a new player join a group only when a new campaign starts?
An adverb for when you're not exaggerating
Why are the trig functions versine, haversine, exsecant, etc, rarely used in modern mathematics?
Circuit to "zoom in" on mV fluctuations of a DC signal?
When a candle burns, why does the top of wick glow if bottom of flame is hottest?
Is "Reachable Object" really an NP-complete problem?
Using audio cues to encourage good posture
How to compare two different files line by line in unix?
Delete nth line from bottom
Do I really need to have a message in a novel to appeal to readers?
Would "destroying" Wurmcoil Engine prevent its tokens from being created?
If my PI received research grants from a company to be able to pay my postdoc salary, did I have a potential conflict interest too?
Do jazz musicians improvise on the parent scale in addition to the chord-scales?
What would be the ideal power source for a cybernetic eye?
Can melee weapons be used to deliver Contact Poisons?
Specialprice & finalprice returns no decimals
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Tierprice decimals displayRemove decimals from configurable option price update scriptFormatting finalPriceRemove price decimals on list and product viewRemove decimals list & product viewi want to write custom sql query to select low and high price in magento2?Prices Zero on listing pages after update to Magento 1.9getFinalPrice returns 0.00 for some configurable productsAfter Plugin does not run at checkoutMagento 2 remove currency symbol and decimals when price is .00
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Magento 2 returns regular price differently from special and final price. Expected result:
$product->getPrice(); // 89,95
$product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue(); // 89,95
$product->getSpecialPrice(); // 49,95
$product->getPriceInfo()->getPrice('special_price')->getAmount()->getValue(); // 49,95
$product->getFinalPrice(); // 49,95
$product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue(); // 49,95
Given result:
$product->getPrice(); // 89,95
$product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue(); // 89,95
$product->getSpecialPrice(); // 49
$product->getPriceInfo()->getPrice('special_price')->getAmount()->getValue(); // 49
$product->getFinalPrice(); // 49
$product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue(); // 49
Somehow the special and final prices get returned without decimals. I tried al kind of things with different helpers (like the taxhelper etc.), but no success. Why does Magento 2.3 keep returning the special price without decimals?
EDIT: And if this is normal behaviour, what would be the proper way to get the special and final price in my module without currency symbols etc. but including tax?
magento2 price magento2.3 special-price
add a comment |
Magento 2 returns regular price differently from special and final price. Expected result:
$product->getPrice(); // 89,95
$product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue(); // 89,95
$product->getSpecialPrice(); // 49,95
$product->getPriceInfo()->getPrice('special_price')->getAmount()->getValue(); // 49,95
$product->getFinalPrice(); // 49,95
$product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue(); // 49,95
Given result:
$product->getPrice(); // 89,95
$product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue(); // 89,95
$product->getSpecialPrice(); // 49
$product->getPriceInfo()->getPrice('special_price')->getAmount()->getValue(); // 49
$product->getFinalPrice(); // 49
$product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue(); // 49
Somehow the special and final prices get returned without decimals. I tried al kind of things with different helpers (like the taxhelper etc.), but no success. Why does Magento 2.3 keep returning the special price without decimals?
EDIT: And if this is normal behaviour, what would be the proper way to get the special and final price in my module without currency symbols etc. but including tax?
magento2 price magento2.3 special-price
add a comment |
Magento 2 returns regular price differently from special and final price. Expected result:
$product->getPrice(); // 89,95
$product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue(); // 89,95
$product->getSpecialPrice(); // 49,95
$product->getPriceInfo()->getPrice('special_price')->getAmount()->getValue(); // 49,95
$product->getFinalPrice(); // 49,95
$product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue(); // 49,95
Given result:
$product->getPrice(); // 89,95
$product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue(); // 89,95
$product->getSpecialPrice(); // 49
$product->getPriceInfo()->getPrice('special_price')->getAmount()->getValue(); // 49
$product->getFinalPrice(); // 49
$product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue(); // 49
Somehow the special and final prices get returned without decimals. I tried al kind of things with different helpers (like the taxhelper etc.), but no success. Why does Magento 2.3 keep returning the special price without decimals?
EDIT: And if this is normal behaviour, what would be the proper way to get the special and final price in my module without currency symbols etc. but including tax?
magento2 price magento2.3 special-price
Magento 2 returns regular price differently from special and final price. Expected result:
$product->getPrice(); // 89,95
$product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue(); // 89,95
$product->getSpecialPrice(); // 49,95
$product->getPriceInfo()->getPrice('special_price')->getAmount()->getValue(); // 49,95
$product->getFinalPrice(); // 49,95
$product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue(); // 49,95
Given result:
$product->getPrice(); // 89,95
$product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue(); // 89,95
$product->getSpecialPrice(); // 49
$product->getPriceInfo()->getPrice('special_price')->getAmount()->getValue(); // 49
$product->getFinalPrice(); // 49
$product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue(); // 49
Somehow the special and final prices get returned without decimals. I tried al kind of things with different helpers (like the taxhelper etc.), but no success. Why does Magento 2.3 keep returning the special price without decimals?
EDIT: And if this is normal behaviour, what would be the proper way to get the special and final price in my module without currency symbols etc. but including tax?
magento2 price magento2.3 special-price
magento2 price magento2.3 special-price
edited 2 days ago
Tober
asked 2 days ago
ToberTober
112
112
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
If you look following class:
vendor/magento/module-catalog/Pricing/Price/SpecialPrice.php
/**
* Returns special price
*
* @return float
*/
public function getSpecialPrice()
$specialPrice = $this->product->getSpecialPrice();
if ($specialPrice !== null && $specialPrice !== false && !$this->isPercentageDiscount())
$specialPrice = $this->priceCurrency->convertAndRound($specialPrice);
return $specialPrice;
Actually following line format price:
$this->priceCurrency->convertAndRound($specialPrice)
Now go to the following class:
vendor/magento/module-directory/Model/PriceCurrency.php
And check the following code
/**
* Round price with precision
*
* @param float $price
* @param int $precision
* @return float
*/
public function roundPrice($price, $precision = self::DEFAULT_PRECISION)
return round($price, $precision);
Check documentation for round as well
Here is the sample example:
<?php
echo round(3.4); // 3
echo round(3.5); // 4
echo round(3.6); // 4
echo round(3.6, 0); // 4
echo round(1.95583, 2); // 1.96
echo round(1241757, -3); // 1242000
echo round(5.045, 2); // 5.05
echo round(5.055, 2); // 5.06
Thank you for your answer! However, the self::DEFAULT_PRECISION seems not to be set or 0. How do I change this to 2? vendor/magento/framework/Pricing/PriceCurrencyInterface.php has: const DEFAULT_PRECISION = 2;
– Tober
yesterday
But the strange thing is that it looks like it has nothing to do with the 'round' function. As you suggest 49,95 would become 50. However, the value that I get returned is 49. Maybe it has something to do with the comma? In the frontend it does show the price as € 49,95. I'm completely lost here.
– Tober
yesterday
Hey, did you debug here? What value return round($price, $precision)?
– Sohel Rana
yesterday
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f270195%2fspecialprice-finalprice-returns-no-decimals%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you look following class:
vendor/magento/module-catalog/Pricing/Price/SpecialPrice.php
/**
* Returns special price
*
* @return float
*/
public function getSpecialPrice()
$specialPrice = $this->product->getSpecialPrice();
if ($specialPrice !== null && $specialPrice !== false && !$this->isPercentageDiscount())
$specialPrice = $this->priceCurrency->convertAndRound($specialPrice);
return $specialPrice;
Actually following line format price:
$this->priceCurrency->convertAndRound($specialPrice)
Now go to the following class:
vendor/magento/module-directory/Model/PriceCurrency.php
And check the following code
/**
* Round price with precision
*
* @param float $price
* @param int $precision
* @return float
*/
public function roundPrice($price, $precision = self::DEFAULT_PRECISION)
return round($price, $precision);
Check documentation for round as well
Here is the sample example:
<?php
echo round(3.4); // 3
echo round(3.5); // 4
echo round(3.6); // 4
echo round(3.6, 0); // 4
echo round(1.95583, 2); // 1.96
echo round(1241757, -3); // 1242000
echo round(5.045, 2); // 5.05
echo round(5.055, 2); // 5.06
Thank you for your answer! However, the self::DEFAULT_PRECISION seems not to be set or 0. How do I change this to 2? vendor/magento/framework/Pricing/PriceCurrencyInterface.php has: const DEFAULT_PRECISION = 2;
– Tober
yesterday
But the strange thing is that it looks like it has nothing to do with the 'round' function. As you suggest 49,95 would become 50. However, the value that I get returned is 49. Maybe it has something to do with the comma? In the frontend it does show the price as € 49,95. I'm completely lost here.
– Tober
yesterday
Hey, did you debug here? What value return round($price, $precision)?
– Sohel Rana
yesterday
add a comment |
If you look following class:
vendor/magento/module-catalog/Pricing/Price/SpecialPrice.php
/**
* Returns special price
*
* @return float
*/
public function getSpecialPrice()
$specialPrice = $this->product->getSpecialPrice();
if ($specialPrice !== null && $specialPrice !== false && !$this->isPercentageDiscount())
$specialPrice = $this->priceCurrency->convertAndRound($specialPrice);
return $specialPrice;
Actually following line format price:
$this->priceCurrency->convertAndRound($specialPrice)
Now go to the following class:
vendor/magento/module-directory/Model/PriceCurrency.php
And check the following code
/**
* Round price with precision
*
* @param float $price
* @param int $precision
* @return float
*/
public function roundPrice($price, $precision = self::DEFAULT_PRECISION)
return round($price, $precision);
Check documentation for round as well
Here is the sample example:
<?php
echo round(3.4); // 3
echo round(3.5); // 4
echo round(3.6); // 4
echo round(3.6, 0); // 4
echo round(1.95583, 2); // 1.96
echo round(1241757, -3); // 1242000
echo round(5.045, 2); // 5.05
echo round(5.055, 2); // 5.06
Thank you for your answer! However, the self::DEFAULT_PRECISION seems not to be set or 0. How do I change this to 2? vendor/magento/framework/Pricing/PriceCurrencyInterface.php has: const DEFAULT_PRECISION = 2;
– Tober
yesterday
But the strange thing is that it looks like it has nothing to do with the 'round' function. As you suggest 49,95 would become 50. However, the value that I get returned is 49. Maybe it has something to do with the comma? In the frontend it does show the price as € 49,95. I'm completely lost here.
– Tober
yesterday
Hey, did you debug here? What value return round($price, $precision)?
– Sohel Rana
yesterday
add a comment |
If you look following class:
vendor/magento/module-catalog/Pricing/Price/SpecialPrice.php
/**
* Returns special price
*
* @return float
*/
public function getSpecialPrice()
$specialPrice = $this->product->getSpecialPrice();
if ($specialPrice !== null && $specialPrice !== false && !$this->isPercentageDiscount())
$specialPrice = $this->priceCurrency->convertAndRound($specialPrice);
return $specialPrice;
Actually following line format price:
$this->priceCurrency->convertAndRound($specialPrice)
Now go to the following class:
vendor/magento/module-directory/Model/PriceCurrency.php
And check the following code
/**
* Round price with precision
*
* @param float $price
* @param int $precision
* @return float
*/
public function roundPrice($price, $precision = self::DEFAULT_PRECISION)
return round($price, $precision);
Check documentation for round as well
Here is the sample example:
<?php
echo round(3.4); // 3
echo round(3.5); // 4
echo round(3.6); // 4
echo round(3.6, 0); // 4
echo round(1.95583, 2); // 1.96
echo round(1241757, -3); // 1242000
echo round(5.045, 2); // 5.05
echo round(5.055, 2); // 5.06
If you look following class:
vendor/magento/module-catalog/Pricing/Price/SpecialPrice.php
/**
* Returns special price
*
* @return float
*/
public function getSpecialPrice()
$specialPrice = $this->product->getSpecialPrice();
if ($specialPrice !== null && $specialPrice !== false && !$this->isPercentageDiscount())
$specialPrice = $this->priceCurrency->convertAndRound($specialPrice);
return $specialPrice;
Actually following line format price:
$this->priceCurrency->convertAndRound($specialPrice)
Now go to the following class:
vendor/magento/module-directory/Model/PriceCurrency.php
And check the following code
/**
* Round price with precision
*
* @param float $price
* @param int $precision
* @return float
*/
public function roundPrice($price, $precision = self::DEFAULT_PRECISION)
return round($price, $precision);
Check documentation for round as well
Here is the sample example:
<?php
echo round(3.4); // 3
echo round(3.5); // 4
echo round(3.6); // 4
echo round(3.6, 0); // 4
echo round(1.95583, 2); // 1.96
echo round(1241757, -3); // 1242000
echo round(5.045, 2); // 5.05
echo round(5.055, 2); // 5.06
answered 2 days ago
Sohel RanaSohel Rana
23.3k34461
23.3k34461
Thank you for your answer! However, the self::DEFAULT_PRECISION seems not to be set or 0. How do I change this to 2? vendor/magento/framework/Pricing/PriceCurrencyInterface.php has: const DEFAULT_PRECISION = 2;
– Tober
yesterday
But the strange thing is that it looks like it has nothing to do with the 'round' function. As you suggest 49,95 would become 50. However, the value that I get returned is 49. Maybe it has something to do with the comma? In the frontend it does show the price as € 49,95. I'm completely lost here.
– Tober
yesterday
Hey, did you debug here? What value return round($price, $precision)?
– Sohel Rana
yesterday
add a comment |
Thank you for your answer! However, the self::DEFAULT_PRECISION seems not to be set or 0. How do I change this to 2? vendor/magento/framework/Pricing/PriceCurrencyInterface.php has: const DEFAULT_PRECISION = 2;
– Tober
yesterday
But the strange thing is that it looks like it has nothing to do with the 'round' function. As you suggest 49,95 would become 50. However, the value that I get returned is 49. Maybe it has something to do with the comma? In the frontend it does show the price as € 49,95. I'm completely lost here.
– Tober
yesterday
Hey, did you debug here? What value return round($price, $precision)?
– Sohel Rana
yesterday
Thank you for your answer! However, the self::DEFAULT_PRECISION seems not to be set or 0. How do I change this to 2? vendor/magento/framework/Pricing/PriceCurrencyInterface.php has: const DEFAULT_PRECISION = 2;
– Tober
yesterday
Thank you for your answer! However, the self::DEFAULT_PRECISION seems not to be set or 0. How do I change this to 2? vendor/magento/framework/Pricing/PriceCurrencyInterface.php has: const DEFAULT_PRECISION = 2;
– Tober
yesterday
But the strange thing is that it looks like it has nothing to do with the 'round' function. As you suggest 49,95 would become 50. However, the value that I get returned is 49. Maybe it has something to do with the comma? In the frontend it does show the price as € 49,95. I'm completely lost here.
– Tober
yesterday
But the strange thing is that it looks like it has nothing to do with the 'round' function. As you suggest 49,95 would become 50. However, the value that I get returned is 49. Maybe it has something to do with the comma? In the frontend it does show the price as € 49,95. I'm completely lost here.
– Tober
yesterday
Hey, did you debug here? What value return round($price, $precision)?
– Sohel Rana
yesterday
Hey, did you debug here? What value return round($price, $precision)?
– Sohel Rana
yesterday
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f270195%2fspecialprice-finalprice-returns-no-decimals%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown