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);
    else
    // 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;
}


Tags:

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:

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

To the system.webServer.handlers section:

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

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!

Tags:

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 :)

Tags:

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!

Tags:

SQL SERVER

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...

Tags:

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"
                        DataFormatString="{0:c}"
                        Expression="{0}-{1}" HeaderText="Net Total" Aggregate="Sum" FooterAggregateFormatString="{0:c}">
                        <ItemStyle HorizontalAlign="right" />
                        <HeaderStyle HorizontalAlign="Right" />
                        <FooterStyle HorizontalAlign="Right" Font-Bold="true"/>
</telerik:GridCalculatedColumn>

Tags:

Telerik

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"/>
                    </telerik:GridNumericColumn>

Tags:

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen

About the author

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

E-mail me Send mail

Calendar

<<  July 2017  >>
MoTuWeThFrSaSu
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456

View posts in large calendar

Recent comments

Tags

Disclaimer

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

© Copyright 2017

Sign in