I'm trying to validate my VBScript function that divides an input value by 1440. When I pass 43.56 as input parameter, it returns me the following result:
0.030250000000000002
while the correct answer is
0.03025
What should I do to make it work correctly both with evenly divided integers, like 1440 / 1440 = 1, and when one value is a decimal. Currently my function looks like so:
Function convertMinutesToDays(value)
If IsNumeric(value) And TypeName(value) <> "Boolean" Then
convertMinutesToDays = value / 1440
Else
convertMinutesToDays = 0
End If
End Function
Actually, if you simply put Response.Write convertMinutesToDays(43.56), it will show 0.03025, but we are using it within an assert javascript method, like so:
Call AssertAreEqual(convertMinutesToDays(43.56), 0.03025, "convertMinutesToDays: pass 43.56 should return 0.03025")
The javascript code:
<script language="JavaScript" runat="server">
function AssertAreEqual(val1, val2, message)
{
var retVal = false;
var divAttributes = "";
var equality = "";
if (val1 === val2)
{
divAttributes = "class=\"unittest assertareequal pass\"";
equality = "=";
retVal = true;
}
else
{
divAttributes = "class=\"unittest assertareequal fail\"";
equality = "!=";
retVal = false;
}
Response.Write("<div " + divAttributes + ">Actual:" + val1 + " " + equality + " " + val2 + ":Expected | " + message + "</div>");
return retVal;
}
</script>
The output:
Actual:0.030250000000000002 != 0.03025:Expected | convertMinutesToDays: pass 43.56 should return 0.03025
Any ideas?