How to change a double to 2 or less decimal places

hi
im trying to change a double to 2 decimal places
the reason is i have a angle that is sesitive to 1.0 x14
and it look rediculas to look at :)
i think on a calculater you use E exponents
but im unsure.

There's a DecimalFormat class. And also Formattable interface. Classes implenting the latter can be formatted using a Formatter which employs the notation common in C and other languages.
String has a format() method that allows a formatted string to be produced, and there are numerous printf() methods in PrintWriter, Console etc
public class RoundingEg {
    public static void main(String[] args) {
        double pi = Math.PI;
            // %.2f means "floating point number with 2 dp"
            // %n means "ewline"
        System.out.printf("%.2f%n", pi);
            // or to obtain a string
        String displayStr = String.format("%.2f", pi);
        System.out.println("Used as any other string: " + displayStr);
}

Similar Messages

  • Help!!!!!  anyone know how to change a Double to an int??

    Help!!!!! anyone know how to change a Double to an int?? for use in an array[int].

    I don't know why would you want to depend on a double value to build your array but programmatically just use plain old cast: i = (int) double_value;
    Keep in mind though, the integer value will be truncated.

  • Change of the quantity field to 5 decimal places in SAP

    Hi Gurus,
    The quantity field is appearing with 3 decimal places in BOM, Process Order, etc. Is it possible to make the decimal places to 5.
    All the decimal digits from SAP are 3 digits. We have an interface through which the data flows from another legacy system (Fow system) to SAP. And the Fow system setting was 5 digits. The issue is some of the raw material requirement qty was really minor and it might be below the decimal 3 digits.
    In that case, when the data flows to SAP from Fow system it will cause the material stage failure. so please help me to investigate how to let the SAP also could have the 5 digits decimal. Thanks.
    Regards
    Brijesh

    Dear ,
    Its SAP standard ,to put and use decimal places in BOM qty .You can use upto 3 decimal places in BOM qty.
    At SE11 you need to see what measure field is linked to the quantity field.Then goto tranaction CUNI and chage the decimal places of the unit of measure for the qty field unit , it will not allow you more than 3 decimal places in case of BOM qty.
    You have following choice :
    1. With the access key make changes in the standard program and take help from ABAPer
    SAPLCSDI, Table Name-RC29P, Field Name- MENGE.
    2) Change the base quantity in BOM header to 1000 aand accordingly change the component quantity.
    Hope this is clear
    Regards
    JH

  • Printing a double to accuracy of 2 decimal places

    Hi,
    I have a double value and I want to print it to an accuracy of 2 decimal places. Is there any way to do this. I tried using the DecimalFormat by
    doing the following
    String str = Double.toString(value);
    DecimalFormat dec = new DecimalFormat(str);
    dec.setMaximumFractionDigits(2);
    String res = dec.toString();But this doesn't seem to work. I am using java 1.4.
    Thanks

    You can use DecimalFormat but like this:
            double value = 1.345678d;
            System.out.println(value);
            DecimalFormat dec = new DecimalFormat("0.00");
            String result = dec.format(value);
            System.out.println(result);Or you can use a BigDecimal where you can specify the most appropriate rounding method:
            BigDecimal bd = new BigDecimal(value);
            bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
            System.out.println(bd.toString());HTH,
    Christian

  • How can I stabilize the DAQ output to four decimal places

    I have a daq 6009. I sent a optical signal. DAQ provides a output which varies in 3rd  decimal place. I done averaging all using a program which I'am attaching with this. So can you please help me in this regard 
    Attachments:
    data acquisition 2 (SubVI).vi ‏71 KB

    You need to find a DAQ with a lower Absolute Accuracy.
    Also, looking at the spec, you can get a better accuracy with a Differential measurement than you can with a RSE.  Apparently the RSE only works in the +-10V range.  By changing to a differential, you can get down to a +-1V range.  That will help your resolution a little bit.  Just wire the ground to the - terminals on the DAQ.
    Another issue could be noise in the system.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Double value truncated to two decimal places without rounding the value.

    I want to truncate double value to two decimal places without doing the rounding of the value.
    Is there any method which can directly do the truncation.

    There's many ways to achieve this such as using
    BigDecimal's setScale method or type-casting. This is
    the way I like to do it:double d = -5.239;
    d = d > 0 ? Math.floor(d * 100) / 100.0 : Math.ceil(d
    * 100) / 100.0;
    Your division by 100 may cause an rounding error, because there are numbers which no finite binary representation. That's splitting hairs! I know ;-)

  • How to change to double click to play song

    Somehow my itunes got changed that when I click on a song (single click) the song starts to play, I used to have to double click the song to play it. I want it changed back to where I have to double click the song to get it to play, is there a setting somewhere I can change?

    There's a DecimalFormat class. And also Formattable interface. Classes implenting the latter can be formatted using a Formatter which employs the notation common in C and other languages.
    String has a format() method that allows a formatted string to be produced, and there are numerous printf() methods in PrintWriter, Console etc
    public class RoundingEg {
        public static void main(String[] args) {
            double pi = Math.PI;
                // %.2f means "floating point number with 2 dp"
                // %n means "ewline"
            System.out.printf("%.2f%n", pi);
                // or to obtain a string
            String displayStr = String.format("%.2f", pi);
            System.out.println("Used as any other string: " + displayStr);
    }

  • How to change email double screen on iPad?

    Hi All,
    As a new iPad user (familiar with iPhone), I am having trouble with the email function.  On the iPhone it shows the mailbox screen only, or the selected email.  The iPad shows both screens, as there is tons of room to do so.  My problem is, I would like the right hand screen blank unless I have opened an email. It seems impossible to do this unless I move all the mail to a mailbox folder.   Once I have done this, I can select a folder, choose an email, finish with it...and then what?  I should have an option to "close" it.   Do I have to re-file it with the folder icon?    I don't want the last email I read staring at me all the time. Please help.
    Bichonlove

    There is no way to do want you want to do. You can't close an email and have the mail app open to an empty window on the right - unless of course you use some workaround like you are doing now. That is one of the limitations of the iPad mail app.
    Another way to do this - another workaround - is just keep and empty folder in the mail app and tap on that folder just before you leave the mail app. It's not a very elegant solution, but it works. And this only works if you have an IMAP email account and you can create additional mailboxes on the iPad.
    Another caveat is that it only works if you leave the mail app (suspend it) and then come back to it. If you close the mail app completely, that will not work either.

  • How to change the name of my computer? Under "places"

    I'm not sure what its called but when i go to my finder and under "places" above "documents, applications, and music" there's something called "dkfsgdifyfj". i guess i typed that in when i first got the computer. I want to change that to something more appropriate but i can't find out how to do that.
    Does anyone know what i can do? sorry for the lack of specifics, i hope someone understands what im saying.
    thank you!

    Welcome to Apple Discussions....be very careful about what you are wanting to do...you are describing the 'Home Directory'....it is where all your personal settings, emails, etc.. are stored...read through and understand the info in these links before attempting anything..
    http://support.apple.com/kb/HT1428?viewlocale=en_US
    http://support.apple.com/kb/TS1876
    http://www.thexlab.com/faqs/renamehomerecovery.html

  • How to change the local decimal separator on windows xp OS ?

    Hi all,
    I would like to known how to change programmatically with LV8.5 the local decimal separator ? I want to force this parameter to the point separator, so to be sure that it's not the comma (if it's the comma when installing the executable, the ascii files are not read properly).
    Thanks.
    Wilfried.

    GerdW wrote:
    Hi Wilfried,
    you can use the format code "%.;" to get points as decimal separator in each string formatting function.
    This is the important one. Put it at the beginning of every format specifier!
    Some functions have a boolean control 'use local decimator' make sure this is 'F'
    Ton
    Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
    Nederlandse LabVIEW user groep www.lvug.nl
    My LabVIEW Ideas
    LabVIEW, programming like it should be!

  • Change IDR currency with decimal place

    Dear Guru,
    Currently in my SAP env, IDR currency setting is set with 0 decimal place.(No decimal Place). However, I have user requirement to change the setting from zero to 2 decimal place. Meaning to say, to have IDR currency maintain in 2 decimal place. What is the effort and is this a big change to the system ? is this change workable ? How will this impact the existing historical data which store IDR amount with no decimal place ?
    Hope to hear from you.
    Regards
    Andrew Tay

    Dear Guru,
    Thank you for your replied. I totally agreed with you, currently my SAP system can maintain up to 15 digits with no decimal place. Beside this digits isues, is there any other areas affected ?
    Thanks in advance.
    Regards
    Andrew Tay

  • How to change data type from Integer to Double?

    In a data set, BIP treat Oracle number type column as Integer. How to change it to double?

    Hi,
    This could be possible with the tcode RSD2 in BW.
    But before you do this you need to remove this KF from the cubes/dso in which they are used.Otherwise i don think you can do this.
    Once the change is done you could add them back to the DataTargets and load the data as required.
    Regards,
    Anoop

  • How to change String to double ?

    I want to change String to double in Applet program, but for the run time, error is occurred.
    It can not find the method parseDouble.
    Error -> Double.parseDouble("7.5");
    I try to test String to Integer, it works fine.
    OK -> Integer.parseInt("7");
    How to change String to double in Applet ?

    Yea, the Double.parseDouble method came in a later release (first time in 1.2).

  • How to change double i = Math.random(); value to (int) value

    I am trying to find out how to convert a given double value to integer, which is, to conver double myNumber = Math.random() to (int) value. Here is the sample program look like this.
    Thank you for the help.
    import javax.swing.JOptionPane;
    public class numbers
    public static void main(String[] args)
    int upperLimit = Integer.parseInt(JOptionPane.showInputDialog
    (null, "Enter the upper range integer."));
    double myNumber = Math.random();
    //Test of Random numbers.
    System.out.println("The Upper random number limit is: " +
    myNumber * upperLimit);
    } //End of main.
    } // End of class.

    Not sure exactly what you want and why you want to change the double to an int. I'm assuming by this you want to generate random integers, from 1 to the upper limit the user enters? If so, this is how I would do it:import java.util.*;
    import javax.swing.*;
    public class Numbers
        public static void main(String[] args)
            int upperLimit = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter the upper range integer."));
            Random r = new Random();
            int myNumber = r.nextInt(upperLimit) + 1;
            System.out.println(myNumber);
    }

  • How to change double to int?

    i got a double
    double x
    x = 3 * 1.2
    how to change x to int type?
    thx a lot

    You can't change x, it's declared as type double.
    You can retrieve the value of x as an int by using a cast:
    int y = (int) x;

Maybe you are looking for