aspose file tools*
The moose likes Beginning Java and the fly likes Need a function that converts a double into a whole int, rounding the decimal and ret Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need a function that converts a double into a whole int, rounding the decimal and ret" Watch "Need a function that converts a double into a whole int, rounding the decimal and ret" New topic
Author

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

Zubi Pen
Greenhorn

Joined: Oct 24, 2007
Posts: 26
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
Ragav Baskaran
Ranch Hand

Joined: Nov 04, 2007
Posts: 36
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 ]
 
wood burning stoves
 
subject: Need a function that converts a double into a whole int, rounding the decimal and ret