This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes Decimal Format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Decimal Format" Watch "Decimal Format" New topic
Author

Decimal Format

Mindy Truitt
Greenhorn

Joined: Sep 07, 2003
Posts: 3
Hi -
After writing the code :
public class Mileage {
public static void main(String[] args) {
DecimalFormat twoDigitsPastPoint = new DecimalFormat("0.00");
double LengthOfTrip, CostOfGas, MilePerGallon, Total;


System.out.print("Enter length of trip: ");
LengthOfTrip = SavitchIn.readLineDouble();
System.out.print("Enter cost of gas: ");
CostOfGas = SavitchIn.readLineDouble();
System.out.print("Enter mile per gallon: ");
MilePerGallon = SavitchIn.readLineDouble();
Total = LengthOfTrip / MilePerGallon * CostOfGas;
System.out.println("The cost of your trip will be: $" + twoDigitsPastPoint.format(Total));
}
}
It won't run because of the error:
java.lang.Error: Unresolved compilation problems:
DecimalFormat cannot be resolved or is not a type
DecimalFormat cannot be resolved or is not a type
at Mileage.main(Mileage.java:17)
Exception in thread "main"
I think it has something to do with the 'DecimalFormat' because that is underlined in my program. Any help would be amazing!! Thanks ~ Mindy
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hi Mindy,
Welcome to JavaRanch!
Strange error messages -- what Java compiler are you using?
Based on just the code you've shown us: including the line
import java.text.DecimalFormat;
at the beginning of the file should fix this problem.


[Jess in Action][AskingGoodQuestions]
Mindy Truitt
Greenhorn

Joined: Sep 07, 2003
Posts: 3
I tried that and it got rid of the DecimalFormat error but now the word Format is underlined. I am using Eclipse as the Complier I think. Thanks ~Mindy
Mindy Truitt
Greenhorn

Joined: Sep 07, 2003
Posts: 3
Thanks, I got it to work I just had to move the line up a bit.
Thanks, MINDY
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Decimal Format