Home>

Nice to meet you.
About the calculation result of the decimal point.
This is what you get when you type:
If i enter 180 ← 1.80 on the input screen, it will be 0 with an error
62
Result screen
180.0
62
BMI 0.0018717546190073662

The result is

.

As a result I want to do
Input screen 1.80
62
Result screen
1.80
62
BMI 18.7175 ...
I would like you to tell me the process to achieve this result.
Please take care.
I'd like advice too,

double num1 = 0;
double num2 = 0;
double resultNum;

try {
num1 = Integer.parseInt (request.getParameter ("num1"));
num2 = Integer.parseInt (request.getParameter ("num2"));
resultNum = num2/(num1 * num1);
BigDecimal bd = new BigDecimal (resultNum);
bd = bd.setScale (1, RoundingMode.HALF_UP);
} catch (NumberFormatException e) {
resultNum = 0;
}
request.setAttribute ("num1", num1);
request.setAttribute ("num2", (int) num2);
request.setAttribute ("resultNum", resultNum);

  • Answer # 1

    "1.80" is not an integer, so Integer.parseInt that converts to an integer is not possible.
    Use Double.parseDouble instead.