Results 1 to 2 of 2
  1. #1
    trill is offline Member
    Join Date
    Jul 2007
    Rep Power

    Default Help with convert a double type number

    Hi, Is there a way in Java that I can convert a double type number such as 3.1111111111222 to only two decimal places? So it would be as 3.11 only?

    Another question is how to do Stop a method from running in Java Code?
    For example.. I'm doing a loop.. and a user input a 'char' type.
    If it's match, it stop execute, other while it keeps going.
    I know have to use input, and if and else statement.
    Which I already did.. But I need a method to stop from running.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Rep Power


    Java Code:
    import java.text.NumberFormat;
    import java.util.Scanner;
    public class Test {
        public static void main(String[] args) {
            NumberFormat nf = NumberFormat.getInstance();
            Scanner scanner = new Scanner(;
            String response;
            do {
                System.out.println("Continue? \"y\"");
                response = scanner.nextLine();
            } while(response.equals("y"));

Similar Threads

  1. how to convert String number to int
    By gabriel in forum New To Java
    Replies: 5
    Last Post: 08-02-2009, 03:46 PM
  2. Replies: 0
    Last Post: 03-01-2008, 10:01 PM
  3. Replies: 7
    Last Post: 01-12-2008, 09:02 PM
  4. convert string to a double?
    By javaMike in forum Advanced Java
    Replies: 2
    Last Post: 11-27-2007, 03:10 AM
  5. Replies: 2
    Last Post: 11-16-2007, 01:24 PM

Posting Permissions

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