• Post Reply Bookmark Topic Watch Topic
  • New Topic

Decimal values  RSS feed

 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a float variable defined and whenever I have a value say "25.49" i get the same value as it is.
When I have a value say "25.40" I get the value without the zero as 25.4. I need the output as 25.40.

basically I want 2 characters after the decimal point, can anyone advise on this.
 
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use System.format, System.out.printf or java.text.NumberFormat.
 
rahulJ james
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not able to acheive that by using these format. Would you mind giving me an example?
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rahulJ james wrote:I am not able to acheive that by using these format. Would you mind giving me an example?


Well, what have you actually tried? There are examples in the JavaDoc, in the Sun Tutorial on the subject, and even found by google, ... if you are stuck, it would be helpful if you tell us where you are stuck.

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