+ 11

How to round a double [Solved]

I've already use Math.Round() but still didn't work https://code.sololearn.com/cB4ArxM88EoV/?ref=app

3rd Feb 2020, 2:46 AM
ZΛRTHΛИ
ZΛRTHΛИ - avatar
5 odpowiedzi
+ 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
KnuckleBars - avatar
+ 7
Benzar Gian Rosales You were right, how stupid i am.
3rd Feb 2020, 2:53 AM
ZΛRTHΛИ
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
hi
4th Feb 2020, 11:20 PM
Borga Borga