I’m using a slightly modified version of the script in < here >
Unity IAP version 1.20.1 (2018-10-5)
Windows 10.
Unity 2018.2.17f1.
Build target is set to Android.
Targeting Android and iOS stores.
When I run in Editor and print the prices in OnInitialized I only get the numbers, no currency symbols.
Unfortunately it’s not an Editor only issue. My app is live, and i’m using isoCurrencySymbol + localizedPriceString, and it’s displaying “USD 0.99” or “NOK 11”.
I can fix it by fetching the CultureInfo from the isoCurrencyCode and formatting using that, but I’d much rather just get the information from the localizedPriceString as the documentation states.
public static System.Globalization.CultureInfo GetCultureInfoFromISOCurrencyCode(string code)
{
foreach (System.Globalization.CultureInfo ci in System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.SpecificCultures))
{
System.Globalization.RegionInfo ri = new System.Globalization.RegionInfo(ci.LCID);
if (ri.ISOCurrencySymbol == code)
return ci;
}
return null;
}
Use it like this
System.Globalization.CultureInfo culture = GetCultureInfoFromISOCurrencyCode(product.metadata.isoCurrencyCode);
if(culture != null) {
button.price.text = product.metadata.localizedPrice.ToString("C", culture);
}
else
{
// Fallback to just using localizedPrice decimal
button.price.text = product.metadata.localizedPrice.ToString();
}
No it doesn’t. The user is correct. On android and Editor at least, there is no dollar sign from localizedPriceString. I am also having to do use the isoCurrencyCode to get desired results. Would be great to have a fix for this.
Edit: Please use product.metadata.localizedPrice to retrieve price(like 9.99), and product.metadata.localizedPriceString to retrieve price and currency code(like $9.99).
I used the workarounds listed above with currency code. But your suggestion seems pretty hacky. Hoping Unity just fixes localizedPriceString to work as expected. Thanks
Please use product.metadata.localizedPrice to retrieve price(like 9.99), and product.metadata.localizedPriceString to retrieve price and currency code(like $9.99).
In my case, Text Mesh Pro’s Font Asset that I am using didn’t contain the currency symbols, that’s why they were not shown.
Solution: Create a Fallback Font Asset that contains all currency symbols, now they’re displayed correctly. Arial & Courier New fonts that comes with Window worked well, however they still miss some symbols. Code2000 font which claims to contain all currency symbol took way too long to set up kerning values so I don’t use it.
Thank you for detailed answer but how to receive all symbols that can be displayed?
I’m using localizedPriceString and for Ukrainian locale the returned value is “19,99грн” so to cover all locales i need to know all value can be returned with the method to include it in Font Asset File to correct displaying.
Is there any documentation?
Ok as i see the easiest way is to find Fonts and create Font Assets that support all signs used by Google Play Billing Services. List of signs From here or here
GoogleProductMetadata meta = GetGoogleProductMetadataExtension.GetGoogleProductMetadata(
product.metadata
);
return meta.localizedPriceString;
I had the same problem, the above worked for me.
It seems that directly accessing the metadata’s localizedPriceString doesn’t work. However, getting GoogleProductMetadata seems to work.
Did anyone ever find a solution for this? Here is my code:
public string FetchLocalizedPrice(string productID)
{
var product = UnityEngine.Purchasing.CodelessIAPStoreListener.Instance.StoreController.products.WithID(productID);
if (product != null)
{
return product.metadata.localizedPriceString;
}
return "Unavailable";
}
and the value being returned is just a number, like 9.99 instead of $9.99. My app is running on both iOS and Android so I don’t want to use the Google solution (even though I couldn’t get that to work).
To confirm, I’m using product.metadata.localizedPriceString and it’s not returning the currency symbol as intended.