• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

comparing numeric field values  RSS feed

 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
I have to write a javascript code wherein , if the amount is greater than 500 and less than or equal to 50000 only then accepted. Here i have written the code for it, still it shows  " amount accepted"  for any value .why  so




 
Marshal
Posts: 67162
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hint: fields values are always strings.

Hint: "amt" is lazy. Why isn't the name "amount"?
 
Sheriff
Posts: 23864
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even if numeric comparisons were being done, it would still always print "amount accepted".

Suppose amount is 0. Then since it's <= 50000, it's accepted. Suppose it's 1000000. Then since it's >= 500, it's accepted. No matter what you try, it's either >= 500 or it's <= 50000. I expect the real requirement was for it to be >= 500 AND <= 50000.
 
Paul Clapham
Sheriff
Posts: 23864
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:I expect the real requirement was for it to be >= 500 AND <= 50000.



Now that I read the original post, that is in fact the real requirement. Sorry for not reading it completely the first time.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!