Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Currency symbol not shown in localizedPriceString

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

  1. seltar_

    seltar_

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

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    2,796
  4. seltar_

    seltar_

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

    JeffDUnity3D

    Unity Technologies

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