Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • 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
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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: 67226
170
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: 24091
54
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: 24091
54
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.
 
Hold that thought. Tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!