Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to preserv Zero in my output  RSS feed

 
Anurag Mishra
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys!!!

I am facing 1 problem, the problem is:
If we define Float f=22.30 and try to print out its value in the console, I get the result as 22.3, it removes the Trailing 0 from the output.
Do anyone have any Idea, how to preserv this zero in my output, I mean to say, how i can get exact value in the output.

Your help will be appriciated.

Regards,

Anurag
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In package java.text, Check out NumberFormat or DecimalFormat.
In Java >= 1.5, PrintWriter and PrintStream of package java.io have
format methods that let you specify decimal places as well.

I wouldn't say this is an advanced question, and more beginner that intermediate.
[ April 04, 2006: Message edited by: Jeff Albertson ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Off to JiG(Beginner).
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is a duplicate of this. PLEASE don't make multiple posts of the same question. You end up wasting people's time when they answer post B what someone else answered in post A.

please read this
[ April 04, 2006: Message edited by: fred rosenberger ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!