-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathMain.java
More file actions
32 lines (19 loc) · 760 Bytes
/
Main.java
File metadata and controls
32 lines (19 loc) · 760 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package main.java;
import java.math.BigDecimal;
import java.math.RoundingMode;
public class Main {
public static double roundToHundredth(BigDecimal num) {
return num.setScale(2, RoundingMode.HALF_DOWN).doubleValue();
}
public static BigDecimal reversAndRound(BigDecimal num) {
return num.negate().setScale(1, RoundingMode.HALF_UP);
}
public static void main(String[] args) {
BigDecimal result1 = new BigDecimal("4.245222");
BigDecimal result2 = new BigDecimal("1.2343");
BigDecimal result3 = new BigDecimal("-1.2343");
System.out.println(roundToHundredth(result1));
System.out.println(reversAndRound(result2));
System.out.println(reversAndRound(result3));
}
}