<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Rajesh's Blog</title>
        <link>http://geekswithblogs.net/rajeshatdotnet/Default.aspx</link>
        <description>Max the Knowledge by Sharing!..</description>
        <language>en-US</language>
        <copyright>Rajesh Thomas</copyright>
        <managingEditor>rajeshemailbox@gmail.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <image>
            <title>Rajesh's Blog</title>
            <url>http://geekswithblogs.net/images/RSS2Image.gif</url>
            <link>http://geekswithblogs.net/rajeshatdotnet/Default.aspx</link>
            <width>77</width>
            <height>60</height>
        </image>
        <item>
            <title>PostBack in ASP.Net showModalDialog</title>
            <category>ASP.Net</category>
            <link>http://geekswithblogs.net/rajeshatdotnet/archive/2008/04/10/121139.aspx</link>
            <description>&lt;p align="justify"&gt;&lt;font face="Verdana"&gt;  &lt;/font&gt;&lt;/p&gt;
&lt;p style="BACKGROUND: white"&gt;&lt;span lang="EN" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-bidi-font-family: Arial; mso-ansi-language: EN"&gt;In my previous project i was using window.showModalDialog to open a modal window (ASPX Page) from parent ASPX page using JavaScript. But whenever the postback occurs in the modal window during &amp;lt;save &amp;gt; button click, it would spawn off a new window. When searching turned up my Colleagues with same problem who managed to work with window.open.Finally i found a solution which is very simple by just including below tag line in the &amp;lt;head&amp;gt; html of the modal window.&lt;/span&gt;&lt;span lang="EN" style="FONT-SIZE: 9.5pt; FONT-FAMILY: Verdana; mso-ansi-language: EN"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="BACKGROUND: white"&gt;&lt;span lang="EN" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-bidi-font-family: Arial; mso-ansi-language: EN"&gt; &lt;strong&gt;&lt;span style="FONT-FAMILY: Verdana; mso-bidi-font-family: Arial"&gt;&amp;lt;base target=_self&amp;gt;&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;span lang="EN" style="FONT-SIZE: 9.5pt; FONT-FAMILY: Verdana; mso-ansi-language: EN"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="BACKGROUND: white"&gt;&lt;span lang="EN" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-bidi-font-family: Arial; mso-ansi-language: EN"&gt;I hope this would be helpful for someone with the same problem.&lt;/span&gt;&lt;span lang="EN" style="FONT-SIZE: 9.5pt; FONT-FAMILY: Verdana; mso-ansi-language: EN"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;img src="http://geekswithblogs.net/rajeshatdotnet/aggbug/121139.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Rajesh Thomas</dc:creator>
            <guid>http://geekswithblogs.net/rajeshatdotnet/archive/2008/04/10/121139.aspx</guid>
            <pubDate>Thu, 10 Apr 2008 13:05:34 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/rajeshatdotnet/comments/121139.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/rajeshatdotnet/archive/2008/04/10/121139.aspx#feedback</comments>
            <slash:comments>30</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/rajeshatdotnet/comments/commentRss/121139.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/rajeshatdotnet/services/trackbacks/121139.aspx</trackback:ping>
        </item>
        <item>
            <title>Formatting Numbers in Javascript</title>
            <category>Javascript</category>
            <link>http://geekswithblogs.net/rajeshatdotnet/archive/2008/04/05/121058.aspx</link>
            <description>&lt;div class="post-body entry-content"&gt;
&lt;p&gt; &lt;/p&gt;
&lt;h2 align="justify"&gt;&lt;span style="FONT-SIZE: 100%"&gt;Formatting numbers for currency display and more.&lt;/span&gt;&lt;/h2&gt;
&lt;p align="justify"&gt;Formatting numbers so they conform to a specific format can be deceivingly tricky. For example, one of the most common tasks is to format a number for currency display- an integer followed by two decimals. There are more subtitles in such a task than many might think. In this tutorial, I'll discuss formatting numbers in JavaScript, such as number rounding, formatting a number for currency display, and more.&lt;/p&gt;
&lt;h3 align="justify"&gt;&lt;span style="FONT-SIZE: 100%"&gt;Number rounding in JavaScript&lt;/span&gt;&lt;/h3&gt;
&lt;p align="justify"&gt;Lets first talk about number rounding in JavaScript. JavaScript accomplishes this with the following method:&lt;/p&gt;
&lt;p align="justify"&gt;&lt;code&gt;Math.round(x)&lt;/code&gt;&lt;/p&gt;
&lt;p align="justify"&gt;Using it, any supplied argument is rounded off to the &lt;strong&gt;nearest integer&lt;/strong&gt;, and using the ".5" up rule. For example:&lt;/p&gt;
&lt;div align="justify"&gt;
&lt;pre&gt;Math.round(25.9) //returns 26&lt;br /&gt;Math.round(25.2) //returns 25&lt;br /&gt;Math.round(-2.58) //returns -3&lt;/pre&gt;
&lt;/div&gt;
&lt;p align="justify"&gt;If purging numbers of decimals is all that you require, class dismissed!&lt;/p&gt;
&lt;h3 align="justify"&gt;&lt;span style="FONT-SIZE: 100%"&gt;Taking things a few decimal further&lt;/span&gt;&lt;/h3&gt;
&lt;p align="justify"&gt;Formatting numbers to specific decimal points still entails Math.round(), but padded with a little multiplication and division. See if you can identify the magic formula involved, with the below examples:&lt;/p&gt;
&lt;div align="justify"&gt;
&lt;pre&gt;var original=28.453&lt;br /&gt;1) //round "original" to two decimals&lt;br /&gt;var result=Math.round(original*100)/100  //returns 28.45&lt;br /&gt;2) // round "original" to 1 decimal&lt;br /&gt;var result=Math.round(original*10)/10  //returns 28.5&lt;br /&gt;3) //round 8.111111 to 3 decimals&lt;br /&gt;var result=Math.round(8.111111*1000)/1000  //returns 8.111&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;p align="justify"&gt;In case you haven't picked up on it, the formula to round any number to &lt;strong&gt;x&lt;/strong&gt; decimal points is:&lt;/p&gt;
&lt;p align="justify"&gt;1) Multiple the original number by 10^x (10 to the power of x)&lt;br /&gt;
2) Apply Math.round() to the result&lt;br /&gt;
3) Divide result by 10^x&lt;/p&gt;
&lt;h3 align="justify"&gt;&lt;span style="FONT-SIZE: 100%"&gt;Formatting numbers for currency display&lt;/span&gt;&lt;/h3&gt;
&lt;p align="justify"&gt;Now, lets move on to formatting numbers for currency display in JavaScript. You may be tempted to simply use number rounding to first shift the number's decimal places (via multiplication), round it, then shift the decimal back (via division) to pound the number into your hard earned dollar, though that won't work in many cases. For example, consider the number 120. Number rounding certainly won't get you to 120.00.&lt;/p&gt;
&lt;p align="justify"&gt;To easily format numbers for a specific number of trailing decimals or total digits (aka padding), JavaScript 1.5 introduces the below two nifty methods: &lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;
    &lt;div align="justify"&gt;&lt;span style="FONT-SIZE: 100%"&gt;Number.toFixed(x) - Formats any number for "x" number of trailing decimals. The number is rounded up, and "0"s are used after the decimal point if needed to create the desired decimal length.&lt;/span&gt;&lt;/div&gt;
    &lt;/li&gt;
    &lt;li&gt;
    &lt;div align="justify"&gt;Number.toPrecision(x) - Formats any number so it is of "x" length. Also called significant digits. A decimal point and "0"s are used if needed to create the desired length.&lt;/div&gt;
    &lt;/li&gt;
&lt;/ol&gt;
&lt;p align="justify"&gt;&lt;span style="FONT-SIZE: 100%"&gt;&lt;strong&gt;Number.toFixed()&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p align="justify"&gt;The best way to see all the subtleties of toFixed() is to see it in action:&lt;/p&gt;
&lt;div align="justify"&gt;
&lt;pre&gt;var profits=2489.8237&lt;br /&gt;profits.toFixed(3) //returns 2489.824 (round up)&lt;br /&gt;profits.toFixed(2) //returns 2489.82&lt;br /&gt;profits.toFixed(7) //returns 2489.8237000 (padding)&lt;/pre&gt;
&lt;/div&gt;
&lt;p align="justify"&gt;Displaying any number in currency format can't get any easier!&lt;/p&gt;
&lt;p align="justify"&gt;&lt;span style="FONT-SIZE: 100%"&gt;&lt;strong&gt;Number.toPrecision()&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p align="justify"&gt;To toPrecision() now:&lt;/p&gt;
&lt;div align="justify"&gt;
&lt;pre&gt;var anumber=123.45&lt;br /&gt;anumber.toPrecision(6) //returns 123.450 (padding)&lt;br /&gt;anumber.toPrecision(4) //returns 123.5 (round up)&lt;br /&gt;anumber.toPrecision(2) //returns 1.2e+2 (you figure it out!)&lt;/pre&gt;
&lt;/div&gt;
&lt;p align="justify"&gt;toPrecision() is useful if your number must be of a certain length.&lt;/p&gt;
&lt;p align="justify"&gt;&lt;span style="FONT-SIZE: 100%"&gt;&lt;strong&gt;Browser considerations &lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p align="justify"&gt;Now, as noted, the last two methods above are JavaScript 1.5 methods. What this means is that they'll only work in IE5.5+ and NS6+. The issue of legacy browsers not performing the desired formatting operation not withstanding, how do you ensure that these two methods at least degrade well? Well, by using method detection in your code. For example:&lt;/p&gt;
&lt;div align="justify"&gt;
&lt;pre&gt;var profits=2489.8237&lt;br /&gt;if (profits.toFixed) //if browser supports toFixed() method&lt;br /&gt;profits.toFixed(2)&lt;/pre&gt;
&lt;/div&gt;
&lt;p align="justify"&gt;For those of you who also need to ensure legacy browsers such as IE5 also perform the desired number formatting operation, well, then it's time to roll your own function.&lt;/p&gt;
&lt;p align="justify"&gt;Well, the toFixed and toPrecision methods are affected by rounding problems and sometimes returns the original number instead of a formatted one in among other browsers ie5.5w. I wrote this prototype for the browsers which doesnt support Javascript 1.5 Methods&lt;br /&gt;
&lt;/p&gt;
&lt;div align="justify"&gt;
&lt;pre&gt;Number.prototype.toDecimals=function(n){&lt;br /&gt;    n=(isNaN(n))?&lt;br /&gt;        2:&lt;br /&gt;        n;&lt;br /&gt;    var&lt;br /&gt;        nT=Math.pow(10,n);&lt;br /&gt;    function pad(s){&lt;br /&gt;            s=s'.';&lt;br /&gt;            return (s.length&amp;gt;n)?&lt;br /&gt;                s:&lt;br /&gt;                pad(s+'0');&lt;br /&gt;    }&lt;br /&gt;    return (isNaN(this))?&lt;br /&gt;        this:&lt;br /&gt;        (new String(&lt;br /&gt;            Math.round(this*nT)/nT&lt;br /&gt;        )).replace(/(\.\d*)?$/,pad);&lt;br /&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;p align="justify"&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div style="CLEAR: both"&gt;&lt;/div&gt;
&lt;/div&gt; &lt;img src="http://geekswithblogs.net/rajeshatdotnet/aggbug/121058.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Rajesh Thomas</dc:creator>
            <guid>http://geekswithblogs.net/rajeshatdotnet/archive/2008/04/05/121058.aspx</guid>
            <pubDate>Sun, 06 Apr 2008 04:54:09 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/rajeshatdotnet/comments/121058.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/rajeshatdotnet/archive/2008/04/05/121058.aspx#feedback</comments>
            <slash:comments>3</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/rajeshatdotnet/comments/commentRss/121058.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/rajeshatdotnet/services/trackbacks/121058.aspx</trackback:ping>
        </item>
    </channel>
</rss>
