Rounding with a given precision

Report a typo

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

Convert an input string to BigDecimal (make BigDecimal instance) and round it towards the "nearest neighbor"; if both neighbors are equidistant, round down. Precision depending 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 Kotlin
import java.math.BigDecimal
import java.math.RoundingMode

fun main() {
// write your code here

}
___

Create a free account to access the full topic