Using international currency and number formats

3 posts, 0 answers
  1. David Penny
    David Penny avatar
    174 posts
    Member since:
    Jun 2006

    Posted 27 Nov 2009 Link to this post


    I don't think this is really a Telerik issue, but I thought someone here might be able to offer some advice.

    I am using telerik input on some web pages, and then changing the International settings on my browser to Dutch (or anything other than English really).  This puts the euro symbol on the currency field as expected and is no problem.  However, the thousands separator then becomes a period (.) and the decimal separator a comma (,).  Again, exactly as expected.  My issue however is when I then take that field and add it to my database, it does not hold it in what I might term a standard decimal format.

    For example, entered on the web page is €0,50 - I want this to be stored internally and in the database as 0.50 so that I can perform standard math functions on it, but it is getting stored as 5.00

    All my web pages as set to culture="auto" and display the correct currency and number formatting when I change the International settings.

    Is there any standard method I should be using to convert values in International currency format into a "standard" decimal format for math operations?

    David Penny
  2. Johny
    Johny avatar
    80 posts
    Member since:
    Aug 2008

    Posted 02 Dec 2009 Link to this post

    Hello David,

    I think that your finding is interesting and decided to try it on my side. However I was not able to reproduce the issue. I set my browser setting to Dutch and changed the culture of my page to "auto" and used the following code:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Culture="auto" %> 
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> 
    <html xmlns=""
    <head id="Head1" runat="server"
        <form id="form1" runat="server"
        <asp:ScriptManager ID="ScriptManager1" runat="server"
        <script type="text/javascript"
            function ClientClick() 
                document.getElementById("Text1").value = $find("<%=RadNumericTextBox1.ClientID %>").get_value(); 
        <telerik:RadNumericTextBox runat="server" ID="RadNumericTextBox1" Type="Currency"
        <asp:Button runat="server" ID="Button1" Text="Get value" OnClientClick="ClientClick();return false;" /> 
        <input type="text" id="Text1" /> 

    After entering 0,50 on the numeric and moving the focus out of it I got the value correctly formatted to € 0,50. Clicking the button then fills the second input with the correct value - 0.50. So is there any other specific that I might be missing?

  3. David Penny
    David Penny avatar
    174 posts
    Member since:
    Jun 2006

    Posted 02 Dec 2009 Link to this post

    Hi Johny,

    Thanks for the response.  I had not tried obtaining the value using Javascript, but am using the returned value client side.

    I have a radnumericinput defined as:
    <telerik:RadNumericTextBox ID="numQuantity" runat="server" AutoPostBack="True">  
                                <NumberFormat AllowRounding="True" /> 

    I found that frequently telerik seems to pick up on my machine's international settings and often appends locale specific information, which I then make sure I look for and strip out.

    Then, when writing this data to SQL I obtain the value:

    Dim decAmount As Decimal = numAmount.Text  
    'Also tried this as well...  
    Dim decAmount As Decimal = Convert.ToDecimal(numAmount.Text)  

    This is where it was returning the wrong information, so I wrapped all this in the following:

        Public Function ToDecimal(ByVal s As String) As Decimal  
            Dim cultureInfo As CultureInfo = cultureInfo.InvariantCulture  
            Dim r As Decimal = 0 
                r = Convert.ToDecimal(s, cultureInfo.NumberFormat)  
            Catch ex As Exception  
                r = 0 
            End Try  
            Return r  
        End Function 

    This now works as I want, so I have written this global function to do this for me whenever I am getting or setting a numeric decimal field on the page and all seems OK now (I use the reverse of the above to set the numeric value, although this generally seems to work OK anyway).

    David Penny
Back to Top