Equivalent code of Mage::app()->getLocale()->getNumber() in Magento2
-
11-10-2020 - |
سؤال
I would like to find out the magento2
equivalent of the below code from magento 1
Mage::app()->getLocale()->getNumber()
Can anyone assist me?
المحلول
inject the class in constructor like below :
protected $_localeFormat;
public function __construct(
\Magento\Framework\Locale\FormatInterface $localeFormat
) {
$this->_localeFormat = $localeFormat;
}
and then use it like :
$value = $this->_localeFormat->getNumber($price);
نصائح أخرى
In magento 2 getNumber()
available in following class..
you can add that class in construct and use it.
Magento\Framework\Locale\Format::getNumber()
لا تنتمي إلى magento.stackexchange