Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-31-2010, 02:40 PM   PM User | #1
visionweb
New to the CF scene

 
Join Date: Jul 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
visionweb is an unknown quantity at this point
Question Comparing decimal numbers

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
visionweb is offline   Reply With Quote
Old 07-31-2010, 02:45 PM   PM User | #2
Dormilich
Senior Coder

 
Dormilich's Avatar
 
Join Date: Jan 2010
Location: Behind the Wall
Posts: 2,863
Thanks: 9
Thanked 291 Times in 287 Posts
Dormilich is on a distinguished road
I don’t see the problem.
__________________
please post your code wrapped in [CODE] [/CODE] tags
Dormilich is offline   Reply With Quote
Old 07-31-2010, 04:17 PM   PM User | #3
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,764
Thanks: 29
Thanked 453 Times in 447 Posts
jmrker will become famous soon enough
Lightbulb

Quote:
Originally Posted by visionweb View Post
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:
Code:
if (var2 < var1)
...
jmrker is offline   Reply With Quote
Old 07-31-2010, 04:30 PM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
A return statement must be within a function.

Code:
<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.

Last edited by Philip M; 07-31-2010 at 05:08 PM..
Philip M is offline   Reply With Quote
Reply

Bookmarks

Tags
comapring decimal number, java script number, number comparing function

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:13 PM.


Advertisement
Log in to turn off these ads.