• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Need a function that converts a double into a whole int, rounding the decimal and ret

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey peeps,

I am new to java and I wanted to know how to make a little function that has a double value and returns a int value in form of a string.
For example,



So after running the function it returns the value: 12,346

Hence this does two things, places a comma afer the three digits and rounds the document in a whole number so 12345.56 becomes 12346

Can anyone help me how to do this.

Thanks,
Zub
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try java.text.DecimalFormat class for formating.
* Use format method

Use java.lang.Math for rounding off numbers.

* Math.round(<double>

Hope this helps.

Thanks
Ragavendran

[ September 02, 2008: Message edited by: Raga Vendran ]
[ September 02, 2008: Message edited by: Raga Vendran ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!