Currency symbol not shown in localizedPriceString

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.

public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
    {
        m_StoreController = controller;
        m_StoreExtensionProvider = extensions;

        foreach (var product in controller.products.all)
        {
            Debug.Log(string.Format("string: {0}", product.metadata.localizedPriceString));
           
            Debug.Log(string.Format("decimal: {0}", product.metadata.localizedPrice.ToString()));
        }
    }

I could just prepend the isoCurrencySymbol, which is what I currently do, but I’d much rather have $ 0.99 than USD 0.99 etc.

Ok, so is there a recommended way of formatting the localizedPrice?

Also, you should update the documentation;

https://docs.unity3d.com/ScriptReference/Purchasing.ProductMetadata-localizedPriceString.html
“Localized price string.
This price is formatted with a currency symbol.”

It is likely an issue only in the Editor. For the Google store for example, we are calling SkuDetails  |  Android Developers

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();
            }
2 Likes

You would want to use localizedPriceString which includes the currency symbol ($, etc) on Android (Google Play). localizedPrice does not.

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.

Please try the following code, I can get the result like: “HK$8.00”

                    Dictionary<string, string> googleProductJSON_dict = this.m_GooglePlayStoreExtensions.GetProductJSONDictionary();
                    string google_intro_json = googleProductJSON_dict[item.definition.storeSpecificId];
                    var productJSON_wrapper = (Dictionary<string, object>)MiniJson.JsonDecode(google_intro_json);

                    object price = "Default price";
                    productJSON_wrapper.TryGetValue("price",out price);

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

Running into this problem still. 2019.3 on Editor. Haven’t tried device yet. Hoping this would “just work”

Please use product.metadata.localizedPrice to retrieve price(like 9.99), and product.metadata.localizedPriceString to retrieve price and currency code(like $9.99).

5952050--637763--upload_2020-6-8_16-34-22.png

1 Like

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.

3 Likes

Yes. That was my issue as well. Check your fonts!

for some reason 0.01 shows in editor but it’s null reference on device

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

2 Likes
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.

Hey @CameronDWills The metadata comes from the store.

Can you confirm you are testing this on an actual device? What platform are you seeing the issue?

Can you check the logs for Unavailable Product errors? That would imply this is caused by an issue fetching from the stores.

Turns out it was just the editor, when testing on device it worked as intended :slight_smile:

1 Like