Tuesday, June 30, 2009

InnerHTML vs InnerText ASP.Net

InnerHTML renders the html.
InnerText does not render html. It just assigns the value to the specified node.

Sample:

string myContent = "<p>Some HTML markup 3 &lt; 5 text </p>";
myDiv1.InnerText = myContent;
myDiv2.InnerHtml = myContent;

myDiv1 will be rendered as "<p>Some HTML markup 3 &lt; 5 text </p>"
myDiv2 will be rendered as "Some HTML markup 3 < 5 text" in a para.

Wednesday, June 24, 2009

Javascript Multiplication Error

When we try to multiply a decimal value with another decimal number or integer, javascript does not seem to handle this well.

for eg: 38.23 * 100 returns 3822.999999999995 instead of 3823.00

To solve this issue we need to use Math.round function

Solution:
Multiply the number by 1000, round it and then divide by 1000. This will give the expected result.

Math.round(1000 * 38.23 * 100) / 1000

Hope this solves the multiplication issue present in javascript and also your time.