• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to display a float number (15.0) to 15 without 0  RSS feed

 
chaohua wang
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, Folks,

I got a float number from database, float n = rs.getFloat("number").

for example. if n=15.5, System.out.prinltn( n ) , so output should is 15.5.

but if the number is 15.0, only if the number is 0 after point, i want it print out like 15 (interger).

How can i do that? Do i need to use some API to convert it to interger?
How can i find the number is 0 after point.

Thank you

Chwang
 
Scott Johnson
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want it print out like 15 (interger).


Use java.text.DecimalFormat.


How can i find the number is 0 after point.


You could convert it to an int and back to a float then compare the result to the original float. If they are equal, the original float was a whole number.
 
chaohua wang
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much.

Chwang
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!