aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes round method Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "round method" Watch "round method" New topic
Author

round method

sarathy rambha
Greenhorn

Joined: Mar 26, 2003
Posts: 2
Hi,
I see compilation while compiling below program. But since round(float) returns int, I am not sure why it thinks return type is double.

float ddd = 3.5;
int j = Math.round(ddd);


Math1.java:84: possible loss of precision
found : double
required: float
float ddd = 3.5;
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35446
    
    9
The message is talking about the first line of code, not the second. "3.5" is a double, and it gets assigned to a float.


Android appsImageJ pluginsJava web charts
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6603
    
    1

The Math class is not part of the exam by the way. As for the error Ulf is right, its on the first line


SCJP 6 articles - SCJP 5/6 mock exams - SCJP Mocks - SCJP 5 Mock exam (Word document ) - SCJP 5 Mock exam in Java.Inquisition format
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12956
    
    3

For float literals, you need to append a letter f to the number, like this:

float ddd = 3.5f;


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: round method
 
Similar Threads
(int)
Math.round question
Round
Math.round() a Tricky Question
Math.round() method