Showing posts with label Mathematics. Show all posts
Showing posts with label Mathematics. Show all posts

Wednesday, 15 April 2009

Math.Log in VBScript

Today I was working on an old Classic ASP project, and I was converting some JavaScript code to ASP.

Part of the code used the JavaScript Math.Pow function, e.g. Math.Pow(4,3), and I needed to do this in classic ASP.

I found that the ^ operator in VBScript does this, but it wasn't easy to transpose into my code, so I just added the following function to the page:

FUNCTION Pow(val, val2)
Pow = val ^ val2
END FUNCTION

Added called it as needed, e.g. Pow(4,3)

Wednesday, 17 December 2008

Javascript parseInt, parseFloat, decide on data type

I was facing an issue today whereby I need to accept a value from an input control, but not knowing what it contained - i.e. a number, a floating point number (decimal) or a string, but I needed to perform maths on it.

With some help of some friends over at forums.asp.net, I came up with the following. You pass it your value, and it will send back the right data type to use on mathematical operations like "+" which normally concatenates strings instead of adding numbers as strings.


function parseValues(aValue)
{
if(isNaN(aValue))
{
return aValue;
}
else
{
if(aValue.indexOf(".")>0)
{
return parseFloat(aValue);
}
else
{
return parseInt(aValue);
}
}
}