6 Replies Latest reply: Feb 9, 2007 9:53 AM by 807599 RSS

    Quick question about decimals

    807599
      I have an inventory program I am working on. The program adds in a restocking fee. When I calculate the restocking fee, I only want two decimal spaces. How do I do this? Here is the code:
      class DVD extends Product implements Comparable {
       private String rating;
       public DVD() {
        super(); //Call the constructor in Product
        rating = ""; //Add the additonal attribute
       }
       public DVD(String name, int number, long stockQuantity, double price, String rating) {
        super(name, number, stockQuantity, price); //Call the constructor in Product
        this.rating = rating; //Add the additonal attribute
           }
           public void setRating(String rating) {
        this.rating = rating;
       }
       public String getRating() {
        return rating;
       }
       public double calculateInventoryValue() {
        return getItemPrice() * getStockQuantity() + getItemPrice()*getStockQuantity()*0.05;
       }
      
       public double calculateRestockFee() {
        return getItemPrice() * 0.05;
       }
       public int compareTo (Object o) {
        Product p = (Product)o;
        return getItemName().compareTo(p.getItemName());
       }
       public String toString() {
        return "Name :"+getItemName() + "\nNumber"+getItemNumber()+"\nPrice"+getItemPrice()+"\nQuantity"+getStockQuantity() +"\nRating :"+getRating()+"\nValue"+calculateInventoryValue();
       }
      }