*
A friendly place for programming greenhorns!
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
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
posted
Sep 02, 2008 06:09:00
0
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,
public String getValueInString() { double value = 12345.56 //I need help to convert the double value into a whole number, rounding the decimal //and then placing a comma after the three digits return value; }
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
posted
Sep 02, 2008 06:25:00
0
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 ]
I agree. Here's the link:
http://aspose.com/filetools
subject: Need a function that converts a double into a whole int, rounding the decimal and ret
Similar Threads
Decimals not converting to correct fractions
Convert double (primitive) value to String
Unpredicatable rounding decimals using Number Format/ Decimal Format
converting a double value
Double Value
All times are in JavaRanch time: GMT6 in summer, GMT7 in winter