In the code, I have
int a = 62;
int b = 132;
double c;
c = (double) a/b;
System.out.println(c);
which prints out the value of c as 0.469696968793869
How can I just keep a short format for c, like 0.4697
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The correct way to keep (not print) a result of prescribed precision is to use the java.math.BigDecimal class as follows.