Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

round method

 
sarathy rambha
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Math class is not part of the exam by the way. As for the error Ulf is right, its on the first line
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15207
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For float literals, you need to append a letter f to the number, like this:

float ddd = 3.5f;
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic