Javascript Format Currency With Parenthesis

by rbellantoni 10/27/2011 11:05:00 AM

All the other javascript functions I have found do not properly format the "$" into the parenthesis. Here is a formatnumber and a format currency function that will take care of everything for you:


function FormatCurrency(num, decimalNum, bolLeadingZero, bolParens) {
    num = FormatNumber(num, decimalNum, bolLeadingZero, bolParens);
    if (num.charAt(0) == "(") {
        num = num.replace("(", "($");
    else {
        num = "$" + num

    return num;
function FormatNumber(num, decimalNum, bolLeadingZero, bolParens)
/* IN - num:            the number to be formatted
decimalNum:     the number of decimals after the digit
bolLeadingZero: true / false to use leading zero
bolParens:      true / false to use parenthesis for - num

RETVAL - formatted number
    var tmpNum = num;

    // Return the right number of decimal places
    tmpNum *= Math.pow(10, decimalNum);
    tmpNum = Math.floor(tmpNum);
    tmpNum /= Math.pow(10, decimalNum);

    var tmpStr = new String(tmpNum);

    // See if we need to hack off a leading zero or not
    if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
        if (num > 0)
        tmpStr = tmpStr.substring(1, tmpStr.length);
    // Take out the minus sign out (start at 2)
        tmpStr = "-" + tmpStr.substring(2, tmpStr.length);

    // See if we need to put parenthesis around the number
    if (bolParens && num < 0)
        tmpStr = "(" + tmpStr.substring(1, tmpStr.length) + ")";

    return tmpStr;
function addCommas(nStr) {
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    return x1 + x2;
function StripNumber(number) {
    number = number.replace("(", "-");
    number = number.replace(")", "");
    number = number.replace(",", "");
    number = number.replace("$", "");
    return number;


Telerik.Web.UI.WebResource.axd' is missing in web.config on IIS7

by ebarcza 10/17/2011 11:39:00 AM

When publishing a project using Telerik controls to IIS 7, you might run in to this error message:

~/Telerik.Web.UI.WebResource.axd' is missing in web.config. RadScriptManager requires a HttpHandler registration in web.config.

You'll need to modify the web config and move the handler from System.Web.HttpHandlers section:

<add path="Telerik.Web.UI.WebResource.axd" verb="*" type="Telerik.Web.UI.WebResource, Telerik.Web.UI" validate="false" />

To the system.webServer.handlers section:

             <add name="Telerik_Web_UI_WebResource_axd" verb="*" preCondition="integratedMode" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" />

The easiest way to accomplishing this is to use the smart tag on the RadScriptManager and click on Register Telerik.Web.UI.WebResource.AXD. See below


This will generate the proper section in your local web.config. You can then either publish it to your server or modify the web.config by hand.

Hope this helps someone!


Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed.

by ebarcza 10/12/2011 9:58:00 AM

When trying to connect to an MDF in Visual studio you might get this error:

Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed.
easy Fix - First you'll need to open up SQL Server Configuration Manager.

Navigate to that in the menu like Microsoft SQL Server 2008 > Configuration tools > SQL Server Configuration Manager. Take a look at figure 1:

Now right mouse click on the highlighted service and goto properties and you'll see the Log On dialogue. set the Log On As to "Local system" as follows:

That should do it! Worked on my machine :)


Cannot be opened because it is version 655. This server supports version 612 and earlier

by ebarcza 10/12/2011 9:42:00 AM

In Visual Studio when I tried to access a SQL MDF on a project a colleague sent me, I received the error "Cannot be opened because it is version 655. This server supports version 612 and earlier". This was due to the fact that I had SQL Express 2005 installed and the MDF was created in SQL Express 2008. The fix for this is simply to install SQL 2008 and tell visual studio to use the new instance name. This can be set through the options menu. Menu>Tools>Options>Database Tools>Database Connections. Hope this helps somebody!



vs 2010 setup.exe: [2] isetupcomponent::pre/post/install() failed in isetupmanager::internalinstallmanager() with hresult -2147467259

by ebarcza 10/12/2011 7:30:00 AM

To solve this recurring issue when trying to install VS 2010 premium from a downloaded ISO, I just used the web installer instead. I never did figure out what the issue was but the web installer succeeded first time. Now digging into the 4.0 framework. Hopefully there are some good nuggets in there...


RadGrid GridCalculated column aggregate - Sum is not supported for type "System.Object"

by ebarcza 10/10/2011 2:19:00 PM

When you try and aggregate a radgrid GridCalculatedColumn, you might encounter this error

Sum is not supported for type "System.Object"



to fix this error all you have to do is give the column a datatype - in my case it was  a decimal. the property setting for this is DataType="System.Decimal". See Example below:

<telerik:GridCalculatedColumn DataFields="SumOfNetRev,SumOfUESFee" DataType="System.Decimal"
                        FilterControlAltText="Filter NetTotal column" UniqueName="NetTotal"
                        Expression="{0}-{1}" HeaderText="Net Total" Aggregate="Sum" FooterAggregateFormatString="{0:c}">
                        <ItemStyle HorizontalAlign="right" />
                        <HeaderStyle HorizontalAlign="Right" />
                        <FooterStyle HorizontalAlign="Right" Font-Bold="true"/>



RadGrid Footer hide text in aggregate

by ebarcza 10/3/2011 1:32:00 PM

use the FooterAggregateFormatString property and set it to something like: FooterAggregateFormatString="{0:c}"

<telerik:GridNumericColumn DataField="SumOfUESFee" DecimalDigits="2" 
                        FilterControlAltText="Filter column column" HeaderText="UES Fee" 
                        UniqueName="UESFee" DataFormatString="{0:c}" Aggregate="Sum" FooterAggregateFormatString="{0:c}">
                        <ItemStyle HorizontalAlign="right" />
                        <HeaderStyle HorizontalAlign="Right" />
                        <FooterStyle HorizontalAlign="Right"/>


Powered by BlogEngine.NET
Theme by Mads Kristensen

About the author

Name of author Author name
Something about me and what I do.

E-mail me Send mail


<<  October 2022  >>

View posts in large calendar

Recent comments



The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2022

Sign in