Results 1 to 3 of 3
  1. #1
    MrPosotive is offline Member
    Join Date
    Sep 2012
    Posts
    68
    Rep Power
    0

    Default I need help rounding

    I really have no clue on how to round. I Need to be able to round up to the nearest hundredth for a program im making for my APCS class so if you guys could help me out, here is the code i already wrote if you need it for whatever reason.
    Java Code:
    import java.io.*;
    import java.util.Scanner;
    
    public class Prog93a
    {
        public static void main(String args[])
        {
            
            Scanner a = new Scanner(System.in);
            System.out.println("Please imput how many Kilo watts used...");
            double aa = a.nextDouble();
            
            double cost = 0.0475;
            
            double baseCharge = aa * cost;
            
            double cityTax = .03 * baseCharge;
            
            double surecharge = .10 * baseCharge;
            
            System.out.println("C O M P S C I Electric");
            System.out.println("--------------------");//20
            System.out.println("Kilowatts Used " + aa + " @ $ " + cost);
            System.out.println("--------------------");
            System.out.println("Base Charge $" + baseCharge);
            System.out.println("Surcharge $" + surecharge);
            System.out.println("Citytax $" + cityTax);
            System.out.println("____");
            System.out.println("Pay this ammount $" + surecharge + baseCharge + cityTax);
            System.out.println("After May 20th Pay $" + (surecharge + baseCharge + cityTax) / .04);

  2. #2
    huupderitis is offline Member
    Join Date
    Sep 2012
    Posts
    8
    Rep Power
    0

    Default Re: I need help rounding

    I'm new to programming as well, however I know that the Math Class in the Java API should help you tremendously. It contains a method Math.Round();

    Let's see... Java Platform SE 6

    Go down and have a look at round... it seems to work for doubles and floating point numbers... Not really sure how to change which place it will round to though!

  3. #3
    Reeling is offline Member
    Join Date
    Jan 2012
    Posts
    49
    Rep Power
    0

    Default Re: I need help rounding

    Check out DecimalFormat and the roundingMode associated with it.

Similar Threads

  1. Rounding calculations
    By lynxbci in forum New To Java
    Replies: 9
    Last Post: 08-20-2011, 03:49 PM
  2. Hey Guys I need some help with rounding...
    By blueduiker in forum New To Java
    Replies: 8
    Last Post: 12-08-2009, 08:58 AM
  3. Rounding
    By Moncleared in forum New To Java
    Replies: 2
    Last Post: 11-17-2009, 08:16 AM
  4. Need help rounding. =/
    By yo1mcool in forum New To Java
    Replies: 1
    Last Post: 10-07-2008, 05:02 AM
  5. Help with java Rounding
    By silvia in forum New To Java
    Replies: 1
    Last Post: 07-20-2007, 07:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •