Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Why is the decimal part 0 when the operation result in java is decimal?
Why is the decimal part 0 when the operation result in java is decimal?
When defining an operand, define it as a floating-point type, and then perform an operation.

Such as: doublenum1= 6;

double num 2 = 4;

Double precision result = num1/num2;

-

When the decimal number is 0:

int num 1 = 6;

int num 2 = 4;

int result = num 1/num 2; (or doubleresult = num1/num2; )

The reason is that num 1 and num2 are integers, and the number obtained after two integer operations is an integer (for example, 1). If a value is assigned to a floating-point variable, just add .0 after the integer (for example, 1.0).