JavaScript (Netbeans): Math & Decimal Format

When you write the equations add .00 to the numbers that are constant (i.e.((TotalPriceWithTaxesFraud-1)/100)+PriceBeforeTaxes) change the 1 to 1.00. It may seem weird but it can cause your values to be changed to integers since you are dividing by and integer. I am not sure if this is true in java it has been a while since I wrote a java app, but other languages will lose precision if you divide or multiply by a value that is not a double or float.

I honestly can't figure it out. A friend of mine in class is working on the same thing so I might be able to see how to incorporate double or float into the equation so that I'm able to get a more accurate number and enter in decimal format of something up to a hundredth. Once I get this done correctly, I will upload my programming so that others can see how to Incorporate it as well.
 
Are you still having issues?

Post your full program and what issues you're having.
 
H'agreed, I'd declare them all as doubles except for the QuantityofItem int (supposedly you'd never buy half an item?):
Code:
double ItemWeight,PricePerPound,TotalPriceWithTaxesFraud,TaxRate,TotalPriceWithTaxesActual,PriceBeforeTaxes;

Might also want to change input.nextInt() to input.nextDouble() for all your double variables too.
 
I found out what my issue was, always something simple and over looked.

Are you still having issues?

Post your full program and what issues you're having.

Code:
//Executes the package statement.
package storeapplication;
//Executes the scanner statement.
import java.util.Scanner;
//Executes the public class statement.
public class StoreApplication {
    // Executes the main method with no parameters.
    public static void main(String[] args) {
        // Executes & displays the welcome text which consists of what we sell and what promotions we are currently holding.
       System.out.printf( "%s\n%s\n%s\n%s\n\n","----------Welcome to Michael's Natural Spring Water----------", "We buy natural spring water directly from Maine and stright \ninto the hands of the customer.", "PROMOTION: 10% off your purchase of more than 100 pounds of \nMichael's Natural Spring Water", "Note: We sell our natural spring water to your weight \nspecifications");
       //Executes the scanner input statement.
       Scanner input = new Scanner( System.in );
       // Prepares all doubles so that a number can be assigned to each double during the mathematics portion.
       double PriceBeforeTaxes;
       int QuantityOfItem;
       int ItemWeight;
       double PricePerPound;
       double TotalPriceWithTaxes;
       double TaxRate;
       //Exectues & displays a request for the quantity of item the user would like to purchase.
       System.out.printf("Total quantity of item you'd like to purchase?                                                   X  ");
       QuantityOfItem = input.nextInt();
       //Executes & displays a request for the quantity in weight the user would like to purchase.
       System.out.printf("How much would you like the packages to weight?                                                LBS  ");
       ItemWeight = input.nextInt();
       //Executes & displays a request for the price per a pound the user would like to pay.
       System.out.printf("Price per pound of item?                                                                     $/LBS  ");
       PricePerPound = input.nextDouble();
       //Executes the if statement if and only if the ItemWeight is less than or equal to 100.
       if(ItemWeight*QuantityOfItem <= 100){
           //Executes & displays the users total before taxes are calculated.
           PriceBeforeTaxes = QuantityOfItem*ItemWeight*PricePerPound;
           System.out.printf("Your total before taxes comes out to...                                                          = $%.2f\n\n", PriceBeforeTaxes);
           //Executes & displays the request for the users local tax rate & calculates it into the final cost.
           System.out.printf("What is your local tax rate?                                                                     = ");
           TaxRate = input.nextDouble();
           TotalPriceWithTaxes = PriceBeforeTaxes*(1+TaxRate);
           System.out.printf("\nYour total with taxes comes out to...                                                  SUB TOTAL = $%.2f\n\n", TotalPriceWithTaxes);}
       //Executes the if statement if and only if the ItemWeight is greater than or equal to 101.
       if(ItemWeight*QuantityOfItem >= 101){
           //Executes & displays the users total before taxes are calculated with a 10% discount.
           PriceBeforeTaxes = (QuantityOfItem*ItemWeight*PricePerPound)/10;
           System.out.printf("Your total with a 10%% discount before taxes comes out to...                                      = $%.2f\n\n", PriceBeforeTaxes);
           //Executes & displays the request for the users local tax rate & calculates it into the final cost with a 10% discount.
           System.out.printf("What is your local tax rate?                                                                     = ");
           TaxRate = input.nextDouble();
           TotalPriceWithTaxes = PriceBeforeTaxes*(1+TaxRate);
           System.out.printf("\nYour total with a 10%% discount after taxes comes out to...                             SUB TOTAL = $%.2f\n\n", TotalPriceWithTaxes);}
    }
}

Double didn't work for me because I only changed the integers INT portion to Double and I didn't change input.nextDouble from input.nextInt. Thank you all for your help. Please take a look at my code and use what you want if your needing to do something similar.
 
H'agreed, I'd declare them all as doubles except for the QuantityofItem int (supposedly you'd never buy half an item?):
Code:
double ItemWeight,PricePerPound,TotalPriceWithTaxesFraud,TaxRate,TotalPriceWithTaxesActual,PriceBeforeTaxes;
Might also want to change input.nextInt() to input.nextDouble() for all your double variables too.

I noticed this while I was in class last week right before this post, hehe. Thanks for the help. =)
 
Back
Top Bottom