• Post Reply Bookmark Topic Watch Topic
  • New Topic

String Buffer problems and questions ?  RSS feed

 
Bilal Ali
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,
We had a requirement that our dobule type variable in java which contains the value 1.4815731879999999E7 , we want to convert it to 1481573.88 , for this purpose I searched on net and found the following code which fulfilee dour purpose:




This code is fulfilling all our requirements but I am totally unable to understand this code , if any one can explain me this code line by line I would be thankful , my first ambugity is what strange arguments is StringBuffer excepting in its constructor , secondaly what is it appending third what is the DecimalFormat . In short some one please explain me this code.

Regards,
bilal Ali.
 
Campbell Ritchie
Marshal
Posts: 56576
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have picked up some old-fashioned code; you ought to be using StringBuilder instead of StringBuffer. And they have used a potentially confusing identifier for it.

Try inserting test lines throughout that snippet:

System.out.println(formatter);//test

You will find more about StringBuilder and about formatting number output in this part of the Java� Tutorials.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!