2 Decimal Places (that's all)

My output from my calculations is:
2.74594
1.343434343434
14.4758395065893849
How can I limit my digits after the decimal point to only 2 places?
Above answers would be:
2.74
1.34
14.47
Would appreciate any help.

Well your code does exactly what you say it will ;-)
It truncates the number to just 2 places.
But if you want to get the "standard" behaviour of ROUND_HALF_UP then you should use Math.round(), as can be seen in the following.for (int i = 0; i < 100; i++) {
  double d = 2.74594 * i;
  double d2 = d;
  double d3 = d;
  //this code truncates to 2 decimal places
  d2 = d > 0 ? Math.floor(d * 100) / 100.0 : Math.ceil(d * 100) / 100.0;
  d3 = Math.round(d * 100) / 100.0;
  System.out.println("d = " + d + "\td2 = " + d2 + "\td3 = " + d3);
}I usually leave doubles at their default precision until I need to presist or present them(to a db for instance), and then I use a class along the following lines...class Formatter {
  public static final int DEFAULT_PRECISION = 2;
  public static final String DEFAULT_PATTERN = "#.00";
  public static final String ZEROS = "0000000000000000";
  public static String convertDoubleToString(Double d) {
    return convertDoubleToString(round(d, DEFAULT_PRECISION), DEFAULT_PATTERN);
  public static String convertDoubleToString(double d) {
    return convertDoubleToString(round(d, DEFAULT_PRECISION), DEFAULT_PATTERN);
  public static String convertDoubleToString(Double d, int precision) {
    return convertDoubleToString(round(d, precision), "#." + ZEROS.substring(precision));
  public static String convertDoubleToString(double d, int precision) {
    return convertDoubleToString(round(d, precision), "#." + ZEROS.substring(precision));
  public static String convertDoubleToString(Double d, String pattern) {
    return new DecimalFormat(pattern).format(d.doubleValue());
  public static String convertDoubleToString(double d, String pattern) {
    return new DecimalFormat(pattern).format(d);
  private static final double round(Double d, int precision) {
    double factor = Math.pow(10, precision);
    return Math.round((d.doubleValue() * factor)) / factor;
  private static final double round(double d, int precision) {
    double factor = Math.pow(10, precision);
    return Math.round((d * factor)) / factor;
}

Similar Messages

  • Round Down (or not at all) and display as percent to 2 Decimal Places

    Hello,
    I have a report in SSRS with a number of computations done in the tablix.  I need to format an expression such that the value will be displayed as a percentage with 2 decimal places that is truncated(not rounded).
    For example,
    0.66666 should be displayed as 66.66% (not 66.67%)
    0.5 should be displayed as 50.00%
     I have done much Googling and have tried everything I can think of but no luck.
    I would appreciate any help anyone can provide.
    Thanks!
    Scott Olander

    Hi Alisa,
    Thanks for your response; it was very helpful.  Unfortunately I'm still having some difficulty...
    When applied to a hardcoded numeric value, your solution seems to work perfectly:
    =Left(0.66666 *100, 5) &  "%" ---> 66.66%
    I had to modify it slightly when applying it to one of my calculations as whole percentages were not displaying .00 to the right of the decimal point.  This is what I modified it to:
    Left(Format((Fields!CorrectAudits.Value/(Fields!InCorrectAudits.Value + Fields!CorrectAudits.Value) * 100),
    "N"), 5) &
    This works perfectly when applied to this particular calculation, but for some reason when I apply it to the following calculation I get funky results:
    Original calculation:
    = SUM(Fields!CorrectAudits.Value)/SUM(Fields!IncorrectAudits.Value + Fields!CorrectAudits.Value)
    Modified calculation:
    =Left((SUM(Fields!CorrectAudits.Value)/SUM(Fields!InCorrectAudits.Value+Fields!CorrectAudits.Value)*100), 5) & "%"
    Results:
    0.66666 ----> 66.66 %   (This is as desired)
    0.25      -----> 25%        (Should be 25.00%)
    0.07692      ------> 7.692 %  (This should be 7.69%)
    Adding the Format "N" piece to this calculation fixes the issues with 0.25 and 0.07962 but causes 0.6666 to round to 66.67% (not the desired result).
    Do you have any ideas?  Am I doing something wrong and just not seeing it?
    Thanks again for your help.
    Scott
    Scott Olander

  • Rounding To Nearest Decimal Place

    Hey Flash Family,
    I am getting the correct output i want but is also giving me
    like 8 numbers after the decimal place...all i want is the numbers
    rounded to the nearest cent meaning only 2 numbers to the right of
    the decimal point....what do i need to add to the current code to
    correct this issue.
    Thanks N Advance

    attach that code to the first frame of your main timeline.
    then anytime you need to change the format of a number like
    _root.how.ROIM.val_tcost use:
    _root.return2DecPlaces(_root.how.ROIM.val_tcost);

  • 11g Client - Inconsistencies at the 16th decimal place

    In TOAD, SQLPlus, & ODBC clients numbers returned from a query are correct (max 3 decimal places)
    In Discoverer & from a report, the numbers are off at the 16th decimal place...
    EG:
    7.081 becomes 7.0810000000000004
    7.090 becomes 7.0999999999999994 (which is exceptionally weird because the rounding doesn't work)
    7.200 becomes 7.2000000000000002
    Any idea what would cause this?
    How can I query from SQLPlus (or TOAD) to confirm whether or not those extended decimal places actually exist in the table?

    Alan3 wrote:
    Maybe I should have added this little tidbit...Please be as verbose as possible (feasible). Show queries etc. - use copy and paste.
    The particular table in question is an interface table that has been in place for 4+ years.
    The columns in question are of data type NUMBER.
    We just switched the PC that runs this interface to Win7 with an 11g client.Describe the interface. E.g. In what program language is it written?
    Now we see the extended decimals with Discoverer (on any PC) and the interface report (an old report built from developer 6) as well, but not from SQL, etc...How is changing one pc client related to the Discoverer and Reports reports? Has the database server been upgraded also? (full version from select * from v$version; )
    Do you see the same change for "old" data (from before the switch).
    I want to know if there is a setting in SQLPlus or the DB client that limits the display of the decimal places that I can alter to determine if the extended decimals actually show up... (they shouldn't be there at all)Both sqlplus and db may affect the outcome, e.g.
    SQL> desc test
    Name                                      Null?    Type
    A                                                  NUMBER
    B                                                  NUMBER(38,5)
    SQL> show numw
    numwidth 10
    SQL>
    SQL> select * from test;
             A          B
         12345      12345
    123456789  123456789
        123,45     123,45
    123,456789  123,45679
         1,234      1,234
    1,23456789    1,23457
    6 rows selected.The same values was inserted to both columns of test. With scale = 5 for its datatype, B values are rounded (4th and 6th row).
    SQL> set numw 5
    SQL> select * from test;
        A     B
    12345 12345
    123,5 123,5
    123,5 123,5
    1,234 1,234
    1,235 1,235
    6 rows selected.The numwidth setting affects sqlplus formatting.
    Edited by: orafad on Jan 5, 2011 9:44 PM

  • Increase decimal places in Gross Unit of Measure

    Hello Everyone,
    I had an issue regarding Decimal places for a specific Unit of measure.
    My Base unit of measure is maintained in Ea. For this the material is maintained with a gross maintained in Kg's. Now to record 2.5 grams i have to menition .0025 Kg but system does not accept up to 4 decimal places. system only accepts up to 3 decimal places. Even increasing the decimal places in CUNI does not make the system to accept 4 Decimal places.
    So what is the solution to this.
    Any help is highly appreciated.
    Sincerely,
    Aji

    HI
    I dont think that we can increase the length of the decimal places filed in all cases. Refer note 95869.
    Regards
    Abhijit Gautam

  • Formatting Numeric Only with Variable Decimal Places

    Acrobat Pro 9, Windows XP
    I'm creating a form that has a number of text box form fields that are to be numeric only per the form requestor. However, for any given field of this type the number of decimal places that can be entered can vary from 0-3 and the requestor does NOT want any unnecessary decimals to appear in the final output (e.g., a "1.2" entry should not appear as "1.200"). The standard number formatting properties always show all the decimal places so I know it's not that route. No calculations will be performed with any of these entries -- the form requestor merely is entering data and then printing it out so that it's legible for the end-user.
    I know that the following line of JavaScript in the Custom Keystroke property limits the entry to numeric only, but how should I tweak the syntax to allow a decimal entry:
         event.rc = (!event.change || /^\d$/.test(event.change))
    I probably also need a script to format for decimal places, but I don't know where to look in the JavaScript for Acrobat API Reference or in the MDN JavaScript Reference.
    Thanks in advance for any assistance.

    Good question. To keep it simple (because there are about 300 form fields in this document), if they choose to add extra decimal zeros, then who am I to argue with their entry. So in your example for a given form field, if they enter "1.200" then I expect that they want "1.200" to display.
    OK, but earlier you said:
    "However, for any given field of this type the number of decimal places that can be entered can vary from 0-3 and the requestor does NOT want any unnecessary decimals to appear in the final output (e.g., a "1.2" entry should not appear as "1.200")."
    This seems inconsistent. Can you clarify? The point is the code and where it's placed depends on this. It could be implemented either as a custom Validate or Format script, in addition to a Keystroke script.

  • Problem with transaction CUNI and configuring decimal places

    Note: I'm actually an ABAP programmer and do not know almost anything about SAP configuration.
    Note2: Sorry if this was posted in the wrong section. I am trying to avoid an ABAP solution so I did not post this in the ABAP section.
    Note3: Sorry for cross posting. I'm trying to make this visible to as much experts as possible.
    \[Problem\]
    I'm tasked to increase the number of decimal places that a certain standard program in MM accepts.
    \[ABAP solution I'm trying to avoid\]
    The consultants' initial recommendation was to make Z copies of the standard table and the standard programs that references that table. This would be rather dangerous as there is the risk of missing certain parts of the code If I was to replace all occurences of the old standard table with my custom Z table.
    \[Standard solution I'm trying to do\]
    Now I've read several threads here that makes use of transaction CUNI to adjust decimal places of certain units of measure (see Re: Unit Of Measure problem and change decimal places in PO quantity). However, when I tried it, It does not work the way I expect it to.
    In SE11, I created a custom table that has a quantity field (length: 13, decimals: 3) and a unit field (length 3)
    In CUNI, I created a new ISO code TST (for test). Then I created a new Unit of measure ZTT (ZTesT) which makes use of my ISO code TST. I set the decimal places to 6.
    When I insert data into my custom table, instead of 6, the number of decimal places remain at 3.
    Please help in adjusting decimal places without touching the table.

    Hello Dzed,
    I've read several posts that suggest transaction CUNI to adjust decimal places in standard unit of measures. What I tried is a simplified simulation of what is needed.
    In a more realistic sense, consider table VBRP and column FKIMG. What If I want to store items in VBRP and allow 6 decimal places for FKIMG but I am not allowed to modify the table? Is making a Z copy of VBRP the only solution? Or is there a more standard way of doing this?
    My worry is that If I copy a table, I also need to copy the programs that use it and modify them accordingly. Our Basis do not want the standard tables touched.
    Kyle

  • CONVERTING DATA TO 2 DECIMAL PLACES

    All,
    I needed to convert a BSO database to only have 2 decimal places. I did this by exporting the data and restricting the export calc to 2 decimal places.
    HOWEVER - there still appears to be rollups that have more than 2 decimal places.
    * Is there an easier way to convert data to 2 decimal places?
    * Is there a "bug" were essbase produces more than 2 decimal places even when all 0 level members have none?
    Thanks

    Old posts never die until they're beaten into the ground...
    On the off chance that someone, anyone still cares, Glenn was absolutely correct when he stated that Essbase stores data as floating point values.
    And when that happens, only values that are divisible by two or 10 are stored without some kind of fractional value.
    See the DBAG: http://download.oracle.com/docs/cd/E17236_01/epm.1112/esb_dbag/dcaintro.html
    Most computers represent numbers in binary, and therefore can only approximately represent real numbers. Because binary computers cannot hold an infinite number of bits after a decimal point, numeric fractions such as one-third (0.3333...) cannot be expressed as a decimal with a terminating point. Fractions with a denominator of the power of two (for example, 0.50) or ten (0.10) are the only real numbers that can be represented exactly. See IEEE Standard 754 for Floating-Point Representation (IEEE, 1985).There is nothing you can do other than handle the round/truncate in the reporting layer.
    You can always take it up with IEEE. :) As we used to say in school when taunting Electrical Engineers, "You can't spell 'geek' without --Cameron-- 'ee'." :) Or hope for an analog computer.
    Regards,
    Cameron Lackpour

  • Altering number of decimal places of formatted number

    Using http://java.sun.com/docs/books/tutorial/i18n/format/numberFormat.html I have worked out how to format a number, almost. When I follow the example in this tutorial that shows how format a double, it always rounds it to 3 decimal places. How do I alter the number of decimal places that this formatting procedure outputs? I used the US as the locale and English as the language. I am assuming that if these parameters are chosen, 3 decimal places is the output. Is this assumption correct?

    Look at the next chapter :)
    http://java.sun.com/docs/books/tutorial/i18n/format/decimalFormat.html

  • Caluclation in P.O. Conditions shall be upto 04 decimal place.

    Hi All,
    Please help me of getting foure decimal points in PO conditions.
    Thanks

    The dec0imal places relating FI only.  The FI people has to configure to require decimal places.  you can try with the following settings in FI.
    1.in OY04 maintain Currency and No.of decimal places required for all purposed.
    2.in OB90 maintain company code, currency and maintain rounding unit.

  • Limiting decimal places

    is there a way to limit the number of decimal places that appear in an output?

    Yes, truncate it manually or by some input method limiter.
    If you are reading a spreadsheet file and outputting that to the console, then you can simply check the value of the string, and determine how many numbers come after the "." charactor. That will give you an index in the string.
    Using that index you can then simply create a new string including the whole number, decimal, and only those points that you want.
    You can also do the reverse and expand the decimals from, let's say 1 decimal (like 10.2) to a 2-digit decimal (like 10.20) by simply adding the needed places in the string after the last charactor.

  • Displaying all numbers with 2 decimal places

    Hi All,
    We have a requirement in our code where we want that all numbers must be diplayed with 2 decimal places.
    Eg: If a number is 21.234 then it should be displayed as 21.23
    If a number is 21.289 then it should be displayed as 21.28
    If a number is 21 then it should be displayed as 21.00
    Can anyone please help me how to do it in a SQL query.
    Regards,
    Shruti

    Hi, Shruti,
    This shows a couple of things you can do:
    COLUMN     trnc     FORMAT     999999.99
    WITH     got_x     AS
         SELECT     empno / 1000     AS x
         FROM     scott.emp
    SELECT     x
    ,     TO_CHAR (x,            '999999.99')     AS tc
    ,     TO_CHAR (TRUNC (x, 2), '999999.99')     AS trnc_tc
    ,     TRUNC (x, 2)                              AS trnc
    FROM     got_x
    ;Output:
    `        X TC         TRNC_TC          TRNC
         7.369       7.37       7.36       7.36
         7.499       7.50       7.49       7.49
         7.521       7.52       7.52       7.52
         7.566       7.57       7.56       7.56
         7.654       7.65       7.65       7.65
         7.698       7.70       7.69       7.69
         7.782       7.78       7.78       7.78
         7.788       7.79       7.78       7.78
         7.839       7.84       7.83       7.83
         7.844       7.84       7.84       7.84
         7.876       7.88       7.87       7.87
           7.9       7.90       7.90       7.90
         7.902       7.90       7.90       7.90
         7.934       7.93       7.93       7.93Column x is the number, as SQL*Plus displays it by default. Note there are as many digits after the decimal point as are needed.
    Column tc shows how TO_CHAR can format the number, with exactly 2 digits after the decimal point. This automatically rounds the number to the nearest multiple of .01, so on the first row (for example) 7.369 gets displayed as 7.37.
    user11272043 wrote:
    ... If a number is 21.289 then it should be displayed as 21.28You (apparantly) always want the number rounded toward 0, so column tc isn't quite what you want.
    Column trnc_tc is exacly what you requested, with the numbr rounded toward 0 (when any rouning is necessry) and 2 digits after the decimal point.
    Column tc is also exactly what you requested, but it uses SQL*Plus formatting rather than SQL. Also, column trnc is a NUMBER, while column trnc_tc is a VARCHAR2, because TO_CHAR, as its name hints, returns a VARCHAR2.
    The SQL*Plus command
    SET   NUMFORMAT  999999.99changes the default format for all number columns. If you use this, you can override it for individual columns by using TO_CHAR (since it returns a VARCHAR2, the NUMFORMAT doesn't apply),or a COLUMN command. Also, if you use SET NUMFORMAT 999999.99, you'll still have to explicitly TRUNC every number, or else 21.289 will come out as 21.29, not 21.28.

  • Anyone know if there's a place on macbooks that store all documents that have been printed?

    anyone know if there's a place on macbooks that store all documents that have been printed?

    http://osxdaily.com/2011/01/20/show-print-history-mac/
    Hope this helps.

  • Does anyone have any idea how do i key in number that contains 20digit, 17 decimal places?

    I need to key in a number that contains at least 17 decimal places using numeric digit control and i need to use expression note as well. Can anyone help?

    After laying down a numeric control right click on it and select "Format and Precision..." to change the number of decimal places. You can also right click and change the "Representation" of the numeric control. By default it will be a DBL which is a 64 bit decimal number with an approximate range of 10**(-308) to 10**308. This is about 15 decimal digits of precision. I know SGL will only give you 10**(-38)to 10**38, which is about 7 decimal digits of precision. Neither of these will cut it for what you are trying to do.
    I would recommend using the Extended Precision (EXT) representation. According to the linked document La
    bVIEW's implementation of the Extended Precision follows the IEEE 80-bit spec(on Windows OSes). Supposedly even the IEEE 128-bit spec(not implemented on the Windows OSes)only gets you 19 decimal places but I am not sure what the limitations of LabVIEW's implementation are. (I found a good table in the LabVIEW help title, "Numeric Data Types Table".)
    I was able to successfully get 17 digits after the decimal point but that was with a leading 0 only before the decimal point. I think you may just be approaching the limit of how a number can be represented in this programming language.
    Anyone else?
    -scraggs99

  • Can not change the number of decimal places in the normalization of result

    dear all
        i want to see the proportion of some data, for example, the income of May is 300, and the total income is 1000, i need to display it like 33.33% . so i set the
    Calculate single values as normalization of result, and then it display 33.333%, i like to display only two number of decimal places, so i set the number of decimal places as 0.00, but i doesn't work, it still display three decimal numbers.
        maybe you say i can use the percentage function like %CT %GT %RT, but i need to allow external access to my query, so the i can not use those functions.
        can somebody helps me ? your advice is appreciated.

    hi,thanks for your advice, but that doesn't suit for my problem.
    before i set the normalization of result, i can change the decimal values. After that i cann't.
    In your thread, someone proposes use the T-code OY04. but this wouldn't help. As i change to other key figure, such as user quantity, when i set normalization of result, it still display 3 decimal values.
    i think the point maybe lie in the normalization of result. please advise... thanks...

Maybe you are looking for

  • Mail Sender Adapter with multiple sMIME attachments

    Hi! I 'm using XI 3.0 SP 15. I have problems with my Mail-Sender-Adapter. The mails, I fetch, contain a certificate and multiple xml-attachments. The xml's represent an IDOC-structure (INVOIC.INVOIC02). The task is to first check the certificate, and

  • Simple SQL query statement is needed

    I need a simple SQL query to fetch records which is existed in all the departments. for example: i want to list the employees which are existed in each and every department.. not sure how should i get those.. will anyone help me please.. thanks in ad

  • Photoshop Elements 13 Not Printing

    Everytime I try to print to either one of my printers, I get an error message that Elements isn't working and needs to close and that Windows is looking for a solution.  When I view my events log, this is what I see: Log Name:      Application Source

  • Fundamental Question about Lightroom and saving images

    I have to laugh as I get ready to pose this question because I've been working with the program for two weeks with Scott Kelby's book and with Lynda.com, and I'm still profoundly confused about what is happening to the photo. To wit: I open a camera

  • Good Issue & Good Receipt

    Hi Members, I am having a requirement like this,we want to generate  Good Issue & Good Receipt Document targeting a Customer or Vendor. because we use that documents for inter division transactions. can any one help me. thank you, saman