Hi all, the question is as my topic. I know there are a lot methods to do that in Java, but is there any class in Java which can directly do this format conversion? Thanks a lot Chris
double d = 5.6789; DecimalFormat df = new DecimalFormat(0.00); String output = df.format(d); // <- equals "5.68" check the API for the description of the possible output formats.
Cindy Glass
"The Hood"
Sheriff
Joined: Sep 29, 2000
Posts: 8521
posted
0
You could multiply by 100. Do a Math.round(); Divide by 100.
"JavaRanch, where the deer and the Certified play" - David O'Meara
Chris Ben
Ranch Hand
Joined: Jan 15, 2001
Posts: 135
posted
0
thanks.
Yogen Vadnere
Ranch Hand
Joined: Sep 20, 2001
Posts: 58
posted
0
I already posted following code in one of the forum, import java.util.* ; import java.text.* ; public class test{ public static void main(String s[]){ double formatDouble = 750.1234 ; NumberFormat converter = NumberFormat.getInstance() ; converter.setMaximumFractionDigits(2); converter.setMinimumFractionDigits(2); System.out.println(converter.format(formatDouble)); } }
Yogen Vadnere
Chris Ben
Ranch Hand
Joined: Jan 15, 2001
Posts: 135
posted
0
It is always nice to know more. Thank you Chris
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: What is a better way to convert 5.6789 to 5.68?