Computer scienceProgramming languagesJavaAdditional instrumentsEssential standard classesStandard classes for computations

BigDecimal

Rounding with a given precision

Report a typo

Write a program that reads two input parameters: the first is a string that represents a big rational number, and the second is a newScale of int type.

Convert an input string to BigDecimal and round it towards the "nearest neighbor"; if both neighbors are equidistant, round down. Precision depends on newScale.

Print the result.

Tip: Use HALF_DOWN mode.

Sample Input 1:

5.666
2

Sample Output 1:

5.67

Sample Input 2:

-3.5
0

Sample Output 2:

-3
Write a program in Java 17
import java.math.BigDecimal;
import java.math.RoundingMode;

class Main {
public static void main(String[] args) {
// write your code here
}
}
___

Create a free account to access the full topic