File tree Expand file tree Collapse file tree 3 files changed +77
-0
lines changed
Expand file tree Collapse file tree 3 files changed +77
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ *
3+ * A java program to convert double to int using
4+ * Double.intValue() method
5+ * @author Gaurav Kukade at coderolls.com
6+ *
7+ **/
8+ public class DoubleToIntUsingIntValueMethod {
9+
10+ public static void main (String []args ){
11+
12+ double doubleValue = 82.14 ; // 82.14
13+
14+ System .out .println ("doubleValue: " +doubleValue );
15+
16+ //create Double wrapper object
17+ Double doubleValueObject = new Double (doubleValue );
18+
19+
20+ //typecase double to int
21+ int intValue = doubleValueObject .intValue (); // 82
22+
23+ System .out .println ("intValue: " +intValue );
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ /**
2+ * A java program to convert double to int using
3+ * Math.round() method
4+ * @author Gaurav Kukade at coderolls.com
5+ **/
6+ public class DoubleToIntUsingRoundMethod {
7+
8+ public static void main (String []args ){
9+
10+ // case 1
11+ double doubleValue = 82.14 ; // 82.14
12+
13+ System .out .println ("doubleValue: " +doubleValue );
14+
15+ //typecase double to int
16+ int intValue = (int ) Math .round (doubleValue ); // 82
17+
18+ System .out .println ("intValue: " +intValue );
19+
20+ System .out .println ();
21+
22+ // case 2
23+ double nextDoubleValue = 82.99 ; //
24+
25+
26+ System .out .println ("nextDoubleValue: " +nextDoubleValue );
27+
28+ // Math.round(nextDoubleValue) returns long value
29+ //typecase long to int
30+ int nextIntValue = (int ) Math .round (nextDoubleValue ); // 83
31+
32+ System .out .println ("nextIntValue: " +nextIntValue );
33+ }
34+ }
Original file line number Diff line number Diff line change 1+ /**
2+ * A java program to convert double to int using typecasting
3+ * @author Gaurav Kukade at coderolls.com
4+ **/
5+ public class DoubleToIntUsingTypecasting {
6+
7+ public static void main (String []args ){
8+
9+ double doubleValue = 82.14 ; // 82.14
10+
11+ System .out .println ("doubleValue: " +doubleValue );
12+
13+ //typecase double to int
14+ int intValue = (int ) doubleValue ; // 82
15+
16+ System .out .println ("intValue: " +intValue );
17+ }
18+ }
You can’t perform that action at this time.
0 commit comments