...

View Full Version : Comparing decimal numbers



visionweb
07-31-2010, 02:40 PM
I am trouble in comparing decimal number.

var1 = 0.25
var2 = 0.50

if (var1<var2)
{
alert("Value is less than minimum")

}
else
{
return true;
}

How can I make it work. Thanks for help in advance

Dormilich
07-31-2010, 02:45 PM
I don’t see the problem.

jmrker
07-31-2010, 04:17 PM
I am trouble in comparing decimal number.

var1 = 0.25
var2 = 0.50

if (var1<var2)
{
alert("Value is less than minimum")

}
else
{
return true;
}

How can I make it work. Thanks for help in advance

If you just trying to get the alert to display, do this:


if (var2 < var1)
...

Philip M
07-31-2010, 04:30 PM
A return statement must be within a function.


<script type = "text/javascript">
function myFunction() {
var1 = 0.25
var2 = 0.50

if (var1<var2) {
alert("Value is less than minimum");
return false;
}
else {
return true;
}
}
myFunction(); // to run the function
</script>

It is a bad idea for obvious reasons to name variables var1 and var2.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum