Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Adam Gerber
/
labJava
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
709af6e4
authored
Apr 03, 2016
by
Adam Gerber
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed more downcasting
parent
318f0bc0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
12 deletions
src/lec01/glab/MoreDownCasting.java
src/lec01/glab/MoreDownCasting.java
View file @
709af6e4
...
...
@@ -17,26 +17,26 @@ public class MoreDownCasting {
System
.
out
.
println
(
"float values"
);
//double to float downcasting
double
l
Value1
=
0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012
;
double
l
Value2
=
101.6546465465464321351654313465123168768546134650646546546546546545645645646545646546546546545646546654564654646546540303212
;
float
fValue1
=
(
float
)
l
Value1
;
float
fValue2
=
(
float
)
l
Value2
;
double
d
Value1
=
0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012
;
double
d
Value2
=
101.6546465465464321351654313465123168768546134650646546546546546545645645646545646546546546545646546654564654646546540303212
;
float
fValue1
=
(
float
)
d
Value1
;
float
fValue2
=
(
float
)
d
Value2
;
System
.
out
.
println
(
String
.
valueOf
(
l
Value1
));
System
.
out
.
println
(
String
.
valueOf
(
f
Value1
));
System
.
out
.
println
(
"As float "
+
String
.
valueOf
(
f
Value1
));
System
.
out
.
println
(
"As double "
+
String
.
valueOf
(
d
Value1
));
System
.
out
.
println
(
"&&&&&&&&&&&&&&&&&&&&&&&&&&&"
);
System
.
out
.
println
(
"As float "
+
String
.
valueOf
(
fValue2
));
System
.
out
.
println
(
"As double "
+
String
.
valueOf
(
dValue2
));
System
.
out
.
println
(
String
.
valueOf
(
fValue2
));
System
.
out
.
println
(
String
.
valueOf
(
lValue2
));
System
.
out
.
println
(
"trucate and then round"
);
System
.
out
.
println
(
"truncate and then round"
);
//truncate by casting to int
System
.
out
.
println
((
int
)
l
Value2
);
System
.
out
.
println
((
int
)
d
Value2
);
//round by rounding
System
.
out
.
println
(
Math
.
round
(
l
Value2
));
System
.
out
.
println
(
Math
.
round
(
d
Value2
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment