Search Unity

Currency symbol not shown in localizedPriceString

Discussion in 'Unity IAP' started by seltar_, Dec 4, 2018.

  1. seltar_

    seltar_

    Joined:
    Apr 16, 2015
    Posts:
    15
    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.
    Code (CSharp):
    1. public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
    2.     {
    3.         m_StoreController = controller;
    4.         m_StoreExtensionProvider = extensions;
    5.  
    6.         foreach (var product in controller.products.all)
    7.         {
    8.             Debug.Log(string.Format("string: {0}", product.metadata.localizedPriceString));
    9.            
    10.             Debug.Log(string.Format("decimal: {0}", product.metadata.localizedPrice.ToString()));
    11.         }
    12.     }
    13.  
    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.
     
  2. seltar_

    seltar_

    Joined:
    Apr 16, 2015
    Posts:
    15
  3. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
  4. seltar_

    seltar_

    Joined:
    Apr 16, 2015
    Posts:
    15
    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.

    Code (CSharp):
    1.  
    2. public static System.Globalization.CultureInfo GetCultureInfoFromISOCurrencyCode(string code)
    3.     {
    4.         foreach (System.Globalization.CultureInfo ci in System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.SpecificCultures))
    5.         {
    6.             System.Globalization.RegionInfo ri = new System.Globalization.RegionInfo(ci.LCID);
    7.             if (ri.ISOCurrencySymbol == code)
    8.                 return ci;
    9.         }
    10.         return null;
    11.     }
    12.  
    Use it like this
    Code (CSharp):
    1.  
    2.  
    3. System.Globalization.CultureInfo culture = GetCultureInfoFromISOCurrencyCode(product.metadata.isoCurrencyCode);
    4.             if(culture != null) {
    5.                 button.price.text = product.metadata.localizedPrice.ToString("C", culture);
    6.             }
    7.             else
    8.             {
    9.                 // Fallback to just using localizedPrice decimal
    10.                 button.price.text = product.metadata.localizedPrice.ToString();
    11.             }
    12.  
     
    ffdev78 and Dawdlebird like this.
  5. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    You would want to use localizedPriceString which includes the currency symbol ($, etc) on Android (Google Play). localizedPrice does not.
     
  6. newatlanta19006

    newatlanta19006

    Joined:
    Feb 23, 2019
    Posts:
    13
    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.
     
  7. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    626
    Please try the following code, I can get the result like: "HK$8.00"

    Code (CSharp):
    1.                     Dictionary<string, string> googleProductJSON_dict = this.m_GooglePlayStoreExtensions.GetProductJSONDictionary();
    2.                     string google_intro_json = googleProductJSON_dict[item.definition.storeSpecificId];
    3.                     var productJSON_wrapper = (Dictionary<string, object>)MiniJson.JsonDecode(google_intro_json);
    4.  
    5.                     object price = "Default price";
    6.                     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).
     
    Last edited: Jun 8, 2020
  8. newatlanta19006

    newatlanta19006

    Joined:
    Feb 23, 2019
    Posts:
    13
    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
     
  9. mangobob4921

    mangobob4921

    Joined:
    Dec 8, 2018
    Posts:
    3
    Running into this problem still. 2019.3 on Editor. Haven't tried device yet. Hoping this would "just work"
     
  10. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    626
    Please use product.metadata.localizedPrice to retrieve price(like 9.99), and product.metadata.localizedPriceString to retrieve price and currency code(like $9.99).
     

    Attached Files:

    Last edited: Jun 8, 2020
    DigitalDurian likes this.
  11. cdr9042

    cdr9042

    Joined:
    Apr 22, 2018
    Posts:
    173
    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.
     
  12. drorco

    drorco

    Joined:
    Nov 20, 2020
    Posts:
    19
    Yes. That was my issue as well. Check your fonts!
     
  13. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    1,085
    for some reason 0.01 shows in editor but it's null reference on device
     
  14. hid_

    hid_

    Joined:
    Apr 5, 2021
    Posts:
    10
    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?
     
  15. hid_

    hid_

    Joined:
    Apr 5, 2021
    Posts:
    10
    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
     
    msakkuzu and ilmario like this.