• Post Reply Bookmark Topic Watch Topic
  • New Topic

Determine If Value is Integer or Float  RSS feed

 
Steve Dyke
Ranch Hand
Posts: 1784
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to get my code to figure out if a value is an Integer or Float to descide how to display but the folowing code returns every thing as Float even when many values are 1.0, 3.0 etc.

 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're using == to compare Strings. Use the equals method instead.
 
Steve Dyke
Ranch Hand
Posts: 1784
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:You're using == to compare Strings. Use the equals method instead.


Thanks. I changed it to the following but still only get Float condition for every thing.

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your premise is flawed. What it sounds like you really want to know is if the value represents a whole number or not. If only there were a mathematical operation that yielded remainders.... (hint hint)
 
Steve Dyke
Ranch Hand
Posts: 1784
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Your premise is flawed. What it sounds like you really want to know is if the value represents a whole number or not. If only there were a mathematical operation that yielded remainders.... (hint hint)


I made the following change but still all Floats

The value of mqArray[2] is 1.00
The value of Math.round(Float.parseFloat(mqArray[2].trim())) = 1

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not what I was hinting at...
 
Steve Dyke
Ranch Hand
Posts: 1784
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Not what I was hinting at...


I think I have it

 
Carey Brown
Saloon Keeper
Posts: 3328
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wondering if you want to treat "0.00" as a float or an int? If so you may need to use regular expressions.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!