Extract currency symbol from currency code Yii - yii

Is there a way we can get the currency symbol from the currency code using some inbuilt formatter in Yii ?
For eg, I pass 'USD' to the function and it returns the dollar symbol ?

You can do it like this
echo Yii::app()->numberFormatter->formatCurrency(56, 'USD');
where 56 is the cost.
More specific information can be found in the yii reference documentation.
Hope this helps.

Related

Smarty operation in Prestashop 1.7

I'm trying to do in Prestashop 1.7 math operation between two smarty variables inside product-discounts.tpl but result is wrong...
{$product.regular_price}
[output: 12,85 €]
{$quantity_discount.discount}
[output: 9.8%]
{$product.regular_price*$quantity_discount.discount}
[output: 117,6] Should be: 12.85*9.8= 125.93
Any idea?
I've tryed:
{$product.regular_price|floatval}
[output:12] Should be: 12.85
Thanks in advance
Prestashop 1.7
Actually, this is happening because of comma in price 12,85 €, so, if you replace the comma with dot then you will get a correct value 125.93
I think the easiest solution would be by assigning a new variable in tpl file and replace the comma from the regular_price 12,85 with a dot.
By the way, you could also replace comma with dots from the controller but if you want to perform mathematical operations within the template file you could do it like this:
Firstly, assign {$product.regular_price} to regularPrice variable along with replacing comma with dot, something like this:
{assign var=regularPrice value=$product.regular_price|replace:',':'.'}
I hope $quantity_discount.discount always contains dot but if there is also a comma instead of dot then,
{assign var=quantityDiscount value=$quantity_discount.discount|replace:',':'.'}
and, last thing you have to do is multiple both variables regularPrice and quantityDiscount with each other
{assign var=total_price value=$regularPrice * $quantityDiscount}
then display total_price in tpl file like this:
{$total_price}
You can use the following
{$product.regular_price_amount*$quantity_discount.discount}
regular_price is used for price display.
If you want to do some mathematical calculation then you can use the regular_price_amount value of the product.

Prestashop Property Combination->quantity is not valid when trying to update combination

Hi I'm trying to update a combination price but always when I save I get the following error:
Prestashop Property Combination->quantity is not valid
Does anyone know how to fix it? I use Prestashop 1.6.1.12
Kind Regards. JDM.
Solved, i forgot that i changed the column quantity to decimal, in the table ps_product_attribute for some tests, i'd changed again to int and works.

Best way to format currency in Yii gridview with no decimals

Can Yii formatCurrency be used to format a currency value in cGridView with zero decimal places?
My current code is:
Yii::app()->locale->numberFormatter->'.'formatCurrency($data["'.$columnName.'"],Yii::app()->params->currency)
Which results in:
$50,000.00
And I want the result to be:
$50,000
Same problem discussed in Yii forum. Here I added some points. Please check the relevant link.
This is due to your locale currency settings. Go and check your YII framework folder/i18n/data you will fix the problem there... Find your locale and fix it.
In ii18n/Cnumberformatter.php
change line 162
$value=round($value,$format['maxDecimalDigits']);
to
$value=number_format($value,$format['maxDecimalDigits'],'.','');
refer this forum.
http://www.yiiframework.com/forum/index.php/topic/21002-formatcurrency-broken/

Problem with Euro formatting (123.456,78) on Microsoft Access Report

On my report in Microsoft Access for all fields I have set-up this code in Control source:
=Replace(Replace(Replace(Format(Sum([NameOfTheField]),"#,###.00"),".",""),",","."),"",",")
and on this way I managed to replace format "123,456.78" to "123.456,78" because I need to have Euro formatting on report.
This code works ok but problem is when some column contains zero value, then I would like to replace "0" with "-" and I don't know how to achieve this?
And help is appreciated and many thanks for prompt replys!
Cheers:)
According to the docs you can specify a distinct/special format for 0 values; I would at least try if "#,###.00" => "#.###,00" does not 'work'.

Automatically Convert Prices on a Web Page to A Different Currency

I am interested in possible methods of automatically converting the prices given when a web page is loaded from the currency given to a specified currency. Ideally, the conversion would also make use of the current exchange rate to give valid prices.
For example, in my specific case, I would like to convert the prices given in Euros (€) on this web site to Sterling (£).
I am looking at using a GreaseMonkey script for this conversion, but can anyone suggest other methods?
Thanks, MagicAndi.
Try the API: http://thecurrencygraph.com
It uses Geo Location scripts to detect the user's country and through that their native currency. It then converts your prices into their currency using the latest exchange rates
Hope this this helps!
W.
Since I dabble in AutoHotkey here's a potential solution using that scripting language, it retrieves the page source from a webpage that does the conversion and parses out the converted value. This requires the httpQuery library to be included:
#Include httpQuery.ahk
InputBox, n, EUR to GBP, Enter the number., , 150, 120
if (ErrorLevel || !n)
return
url := "http://www.xe.com/ucc/convert.cgi?Amount=" n "&From=EUR&To=GBP&image.x=55&image.y=8"
html := URLDownloadToVar(url)
Gui, Add, Edit, w125, % RegExMatch(html,"[\d\.]+(?= GBP)",m) ? m "£" : "The value could not be retrieved."
Gui, Show, AutoSize Center, GBP
VarSetCapacity(html,0)
Return
GuiClose:
GuiEscape:
Gui, Destroy
return
URLDownloadToVar(url){
if !RegExMatch(url,"^http://")
url := "http://" url
httpQuery(html,url)
VarSetCapacity(html, -1)
Return html
}
There are obviously more thorough (and complex) methods for solving this problem but this at least solves it with minimal effort.
The quick and easy answer is to make use of a Firefox add-on. There are a number of currency converters available as add-ons, but I ended up using Exch, as it suited my needs best.