+ 1
Java
In java How to write program to round off decimal(Float , double) to nearest int value, Without using any method Anybody have idea plz tell me
6 Answers
+ 3
Math.round -> round to nearest value.
eg- 5.3 to 5.0 and 5.7 to 6.0
Math.floor -> round to nearest lower limit.
eg- 5.6 to 5.0
Math.ceil -> round to nearest upper limit.
eg- 5.2 to 6.0
+ 2
To understand what you need more, Can you share your try?
Edit:
double a=3.45;
a=a-a%1; //floor
a=(a-a%1)+1; //ceil
0
Put some efforts first. Share your code here and we will help you out in solving the errors.
Hint: try type casting.
0
i had put i solved using
type casting
then Math.round
nd then Math.floor
i jus want differentiation
0
"Without using any method" so you can't use Math functions
(type casting) is good way, +1 if dec%1>=0.5
then solve negative sign for -2.55 -> -3.0
0
thnq