Skip to content

Instantly share code, notes, and snippets.

@RuslanAsadov
Last active September 28, 2020 16:35
Show Gist options
  • Save RuslanAsadov/004ed1f615e3683ad5c23fd41d3c0d2f to your computer and use it in GitHub Desktop.
Save RuslanAsadov/004ed1f615e3683ad5c23fd41d3c0d2f to your computer and use it in GitHub Desktop.
<?php
$fmt = new NumberFormatter( 'ru_RU', NumberFormatter::CURRENCY );
$fmt->setAttribute(NumberFormatter::FRACTION_DIGITS, 0);
$fmt->setSymbol(NumberFormatter::CURRENCY_SYMBOL, '₽');
$price = $fmt->formatCurrency($price, "RUR")."\n";
// Function
function beauty_price_value($value = 0, $currency = 'rub') {
$locale = 'ru_RU';
$currency_slug = 'RUR';
if($currency == 'usd') {
$locale = 'en_US';
$currency_slug = 'USD';
}
if($currency == 'eur') {
$locale = 'en_US';
$currency_slug = 'EUR';
}
$fmt = new NumberFormatter($locale, NumberFormatter::CURRENCY);
if($currency == 'rub') {
$fmt->setSymbol(NumberFormatter::CURRENCY_SYMBOL, '₽');
}
$fmt->setTextAttribute(NumberFormatter::CURRENCY_CODE, $currency_slug);
$fmt->setAttribute(NumberFormatter::FRACTION_DIGITS, 0);
return $fmt->formatCurrency($value, $currency_slug);
}
const formatter = new Intl.NumberFormat('ru-RU', {
style: 'currency',
currency: 'RUB',
minimumFractionDigits: 0,
})
const price = formatter.format(val)
// Format to Rubles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment