Click here to Skip to main content
15,867,594 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have tried the following...
Java
public static void String Detail()
{  
  double minute = duration /60; 
  return minute.ToString();
}
Posted
Updated 25-Feb-15 8:27am
v3

Java
public static void String Detail()

I'm even surprised this compiles. What is the return type of your method? void or String?

Another question is: is your issue finding the number of minutes from a duration, or displaying a string representation of a double number?

If you're struggling with computing the number of minutes from a number of seconds, then it's definitely:
Java
public static double minutesFromSeconds(int seconds) {
   return seconds / 60.0;
   // Here we use the 60.0 notation so that we compute a real division,
   // not an integer one
}


If your issue is getting a string representation of a double number, then it is as trivial as:
Java
String result = minutes.ToString();


The important thing is: never work with any number as a string. Only use a string representation when you need to present it to the user. Using strings to handle numbers in code is one of the worst practices ever.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 25-Feb-15 16:13pm    
No wonder some moron down-voted our both answers. (Anonymous voter has every right to down-vote anonymously, but, I think, no right to get offended, as this is "nobody", right? ;-)
I did not even noticed that there were two return types (void and String, very nice), so I credited your answer. :-)
My 5.
—SA
phil.o 26-Feb-15 1:11am    
Thank you Sergey :)
Aha, static method using undeclared duration. How so? Is it also static? Bad idea. Pass duration as a parameter to the method, after all…
But even if you fix it, such method makes too little sense, but this is a different story.

[EDIT]

And sorry, I did not notice that "void" and "string" are two different return types, so it cannot compile. I noticed it only thanks to Solution 2.

Thank you for accepting the answers formally. Please call again if you have other questions.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900