Welcome to Mediachase Community Sign in | Join | Help    
in Search   

Decimal places

Last post Fri, Apr 27 2007, 3:00 AM by alexey.antonov. 9 replies.
Sort Posts: Previous Next
  •  Mon, Apr 03 2006, 10:49 AM 2656

    Decimal places

    Hi,
    I would like to display prices without decimal, like this   "9.900 kr"  instead of "9.900,00"
    Are there any settings that I can adjust to change this?

    Thanks,
    GG
  •  Mon, Apr 03 2006, 12:08 PM 2658 in reply to 2656

    Re: Decimal places

    The currency is displayed using Mediachase.Store.Business.CurrencyManager.ConvertCurrency method, which calls FormatCurrency method which returns the formatted string representing the price. This is done using the following format method of String class:

    String.Format(EffectiveCulture(currencyCode), "{0:c}", amount);

    Basically it is using the currency format. The currency format is defined by the operating system so it won't be easy to change. You will need to modify "{0:c}" section of the Format attributes to display it as you wish. Good thing be to not modify how it is formatted for the admin site:

    if(FrameworkConfig.OperationMode == "Admin")

       return String.Format(EffectiveCulture(currencyCode), "{0:c}", amount);

    else

       return String.Format(EffectiveCulture(currencyCode), "{#,##0}", amount);

    Hope this helps,
    Sasha.

  •  Mon, Apr 03 2006, 2:06 PM 2660 in reply to 2658

    Re: Decimal places

    I expect that I need the full source code for that, right?

    GG
  •  Tue, May 30 2006, 11:04 AM 2907 in reply to 2660

    Re: Decimal places

    Try changing the Base Currency property in the administration->global settings page.

    Thanks,
    Sasha.

  •  Tue, May 30 2006, 11:14 AM 2908 in reply to 2907

    Re: Decimal places

    I have the base currency set to ISK, which is the currency that I use. 
    All prices are still displayed as "123.456,00 kr." but I want it to be displayed as "123.456 kr."

    /GG
  •  Tue, May 30 2006, 11:44 AM 2909 in reply to 2908

    Re: Decimal places

    Put the following into the global.asax.cs file for the public store:

    protected void Application_BeginRequest(Object sender, EventArgs e)

    {

    System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalDigits = 0;

    }

    Thanks,
    Sasha.

  •  Tue, May 30 2006, 3:37 PM 2910 in reply to 2909

    Re: Decimal places

    Excellent !
    This did the trick.  Thanks alot.

    /GG
  •  Sun, Apr 22 2007, 9:02 AM 5491 in reply to 2910

    Re: Decimal places

    Hi,
    I now have the same issue but this time on a version 4.

    I tried to solve it in the same way as I did in version 3 by adding these lines in global.asax:

    protected void Application_BeginRequest(Object sender, EventArgs e)
        {
            System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalDigits = 0;

        }
       
    but then I get the result below when I try to open the site.

    Should I use a different approach? As before I just want to display the currency amounts with 0 decimals.

    /GG

    Server Error in '/Direct/PublicStore' Application.

    Instance is read-only.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.InvalidOperationException: Instance is read-only.

    Source Error:

    Line 58:     protected void Application_BeginRequest(Object sender, EventArgs e)
    Line 59: {
    Line 60: System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalDigits = 0;
    Line 61:
    Line 62: }

    Source File: c:\data\dev\hermes\Direct ecf base 4.0.10\PublicStore\Global.asax    Line: 60

    Stack Trace:

    [InvalidOperationException: Instance is read-only.]
    System.Globalization.NumberFormatInfo.set_CurrencyDecimalDigits(Int32 value) +68
    ASP.global_asax.Application_BeginRequest(Object sender, EventArgs e) in c:\data\dev\hermes\Direct ecf base 4.0.10\PublicStore\Global.asax:60
    System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +92
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64


    Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210

  •  Thu, Apr 26 2007, 12:08 PM 5519 in reply to 5491

    Re: Decimal places

    It looks like that property was changed to readonly in asp.net 2.0 framework. I'm not sure why, but it will require further investigation.

    Thanks.

  •  Fri, Apr 27 2007, 3:00 AM 5523 in reply to 5519

    Re: Decimal places

    Try to use the following variant of function FormatCurrency:

    public static String FormatCurrency(decimal amount, string currencyCode)
    {
             
    CultureInfo cult = EffectiveCulture(currencyCode);
             
    cult.NumberFormat.CurrencyDecimalDigits = 0;
             
    return String.Format(cult, "{0:c}", amount);
    }

    Alexey Antonov,
    Mediachase

View as RSS news feed in XML
Site Terms | Privacy Policy | About Us | Contact Us
Running on Mediachase eCommerce Framework 4.0.
  Copyright © Mediachase, LTD. 1997-2006. All Rights Reserved

E-commerce, HelpDesk, Service Desk & Project Management Software, alternatives to Microsoft Project Server & Sharepoint Collaboration Server
project management software | microsoft project server | sharepoint collaboration server | issues management, helpdesk & service desk
Powered by Community Server, by Telligent Systems