-
Notifications
You must be signed in to change notification settings - Fork 150
Expand file tree
/
Copy pathMain.java
More file actions
29 lines (24 loc) · 805 Bytes
/
Main.java
File metadata and controls
29 lines (24 loc) · 805 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
package com.ironhack;
import java.math.RoundingMode;
import java.math.BigDecimal;
public class Main{
public static void main(String[] args) {
BigDecimal number1 = new BigDecimal("1.2345");
double result1 = roundedToHundredth(number1);
System.out.println(result1);
BigDecimal result2 = reverseAndRound(number1);
System.out.println(result2);
}
public static double roundedToHundredth(BigDecimal number){
if (number == null) {
return 0.0;
}
return number.setScale(2, RoundingMode.HALF_UP).doubleValue();
}
public static BigDecimal reverseAndRound (BigDecimal number){
if (number == null) {
return null;
}
return number.negate().setScale(1, RoundingMode.HALF_UP);
}
}