How to round a double [Solved] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 11

How to round a double [Solved]

I've already use Math.Round() but still didn't work

3rd Feb 2020, 2:46 AM
ZΛRTHΛИ - avatar
5 Answers
+ 3
I think that it Math.Round does not change the value of the variable but instead returns the rounded value
3rd Feb 2020, 2:51 AM
KnuckleBars - avatar
+ 7
Benzar Gian Rosales You were right, how stupid i am.
3rd Feb 2020, 2:53 AM
ZΛRTHΛИ - avatar
+ 5
public class rounding { public static void main(String[ ] args) { double a = 12.765; int b = (int) Math.round(a); System.out.println(b); }} This is the Syntax used to round a double into an Integer , then printing the rounded value on the screen ; Actually in this piece of code we ae casting the Double value into an Integer by using Math class to round it .
3rd Feb 2020, 8:47 PM
Naser Mohammed Alsayegh
- 1
4th Feb 2020, 11:20 PM
Borga Borga