How to decide number of decimals

Hi!
I wonder how I can decide how many decimals I want. I write a program where I use doubles, but there is no limit on how many decimals I get. How can I limit the decimal the easiest way?
for instance like this:
double a = 1.23
double b = 1.46
double c = a * bWhere c is in format x.xx (eg 2.34).
Also, is there a way to e.g tell that you want 2 decimals, but if the number you get is an integer (eg. 1), it will only say 1 and not 1.00.
Thank you in advance.

Cissi wrote:
Also, is there a way to e.g tell that you want 2 decimals, but if the number you get is an integer (eg. 1), it will only say 1 and not 1.00.There sure is, but this depends on your interpretation of what the double being an integral value means. You never want to deal with absolute == operations on doubles.
This is a way of telling whether a double is an integral value to 5 decimal places:
double a = 3.000006;
int factor = 100000;
if ( Math.round(a) * factor == (int) (a * factor) ) {
   //a is an integer to 5 decimal places
}There are probably better ways to do this though; I don't use floating point numbers all that much in what I do.
edit I threw up a bit in my mouth after I read what I wrote there. Please don't use that. I wouldn't.
Edited by: endasil on Dec 20, 2007 9:53 AM

Similar Messages

  • How to change number of decimals in percentage agreement rebates

    Hi,
    I'm searching for a solution to have percentage amounts with 5 decimals instead of 3, in the conditions of rebate agreements.
    That's concerning transactions VBO1, VBO2, VBO3.
    Thanks for help.

    dear bras
    refer this
    Changing Data Types and Lengths of Existing Fields
    If a  data element is assigned to the field, you must change the technical field attributes (data type, length, number of decimal places) in the domain of the data element.
    Procedure for Fields with Data Elements
    Double-click on the name of the data element.
    The data element maintenance screen appears.
    Double-click on the name of the domain.
    The domain maintenance screen appears.
    Choose Domain ® Display ® Change.
    Make the required changes and save your entries.
    Note that this change affects all the table fields that refer to the particular domain. Foreign keys could become inconsistent and conversions required. You should therefore consider the effects of this action before changing the domain by choosing  in the maintenance screen of the domain and checking if the domain is used in other tables.
    Choose .
    The table is activated again and the table field is adjusted to the domain change.
    Procedure for Fields with Direct Type Entry
    Place the cursor on the field and choose Data element / Direct type.
    Values can now be entered in fields Data type, Length, DecPlaces and Short text.
    Change the entries for the data type, length and possibly the number of decimal places.
    Save your entries.
    Choose .
    Note that a table conversion will normally be necessary (see  Adjusting Database Structures) if you change the field attributes.
    rewards if it helps
    siva

  • How to shorten number of decimals

    I need to show only 2 decimals and can't because i'm using double variables. Can anyone tell me how to get readout of only 2?
    Here is my code:
    public class Applet
    public static void main(String [] args)
    int pValue =200000;
    int nPeriod = 30*12;
    double iRate = 5.75/100/12;
    double payMent = 0;
    System.out.println("Payment Calculator");
    //calculations
    payMent = (pValue * iRate) / (1 - Math.pow(1 + iRate, - nPeriod));
    System.out.println("Your Payment is " + payMent);
    }

    Thank you for your quick help. :)
    I found a solution on the net that corresponds with your suggestion and it worked. http://www.scit.wlv.ac.uk/~jphb/java/arith1.html Since I'm new to programming, having the syntax helped.
    Thank you!!!!
    NumberFormat layout = NumberFormat.getNumberInstance();
         layout.setMaximumFractionDigits(2);
    String outstr = layout.format(payMent);

  • Hello does anyone knows how to re-enter the decimals for the tempo cause i only have a full number and can't enter a decimal number ?

    hello does anyone knows how to re-enter the decimals for the tempo cause i only have a full number and can't enter a decimal number ?

    Hi
    Go to Preferences:Display and check that you have:
    HTH
    CCT

  • How can we specify the number of decimals to be printed

    How can we specify the number of decimals to be printed
    such as "%5.2d" in C.
    Can anyone help me

    You could use the DecimalFormat or NumberFormat to do the job.
    double number 1234.567;
    DecimalForamt df = new DecimalFormat("###.##");
    String s = df.format(number);or
    double number 1234.567;
    NumberFormat nf = NumberFormat.getNumberInstance();
    nf.setMaximumFractionDigits(2);
    /* if needed.
       nf.setMaximumIntegerDigits(value);
       nf.setMinimumFractionDigits(value);
       nf.setMinimumIntegerDigits(value); */
    String s = nf.format(number);I didn't test the codes but they should work. For more information, please consult the documentations.

  • How to find number of lines in an internal table

    Dear all,
    how to find number of records present in an internal table.

    DESCRIBE TABLE
    Syntax
    DESCRIBE TABLE itab [KIND knd] [LINES lin] [OCCURS n].
    Extras:
    1. ... KIND knd
    2. ... LINES lin
    3. ... OCCURS n
    Effect
    This statement determines some properties of the internal table itab and assigns them to the specified variables. The various additions enable you to determine the table type, the number of currently filled rows and the initial memory requirement.
    In addition, the system fields sy-tfill and sy-tleng are filled with the current number of table rows and the length of a table row in bytes.
    Notes
    For detailed information about an internal table, you should use the methods of RTTS of the DESCRIBE TABLE statement.
    Without the specification of an addition, the statement DESCRIBE TABLE only sets the system fields sy-tfill and sy-tleng.
    Addition 1
    ... KIND knd
    Effect
    The table type of the internal table itab is determined and a corresponding one-digit identification is assigned to the data object knd. A character-type data type is expected for the data object. The identifications are "T" for standard tables, "S" for sorted tables and "H" for hashed tables. These values are also defined as constants sydes_kind-standard, sydes_kind-sorted, and sydes_kind-hashed in the type group SYDES.
    Addition 2
    ... LINES lin
    Effect
    The current number of table rows of the internal table itab is determined and is assigned to the data object lin.The data type i is expected for the data object.
    Note
    As of release 6.10, the current number of rows of an internal table can also be determined using the in-built function lines.
    Addition 3
    ... OCCURS n
    Effect
    The initial memory requirement defined during the creation of the internal table with the addition INITIAL SIZE or the obsolete addition OCCURS is determined and assigned to the data object n. The data type i is expected for the data object.
    Example
    Descending sorting of a generically typed internal table in a subprogram. Since sorted tables cannot be sorted in a descending order, the table type is checked to avoid an exception that cannot be handled.
    TYPE-POOLS sydes.
    FORM sort_descending CHANGING itab TYPE ANY TABLE.
      DATA tabkind(1) TYPE c.
      DESCRIBE TABLE itab KIND tabkind.
      IF tabkind = sydes_kind-standard OR
         tabkind = sydes_kind-hashed.
        SORT itab DESCENDING.
      ELSEIF tabkind = sydes_kind-sorted.
        MESSAGE '...' TYPE 'E'.
      ELSE.
        MESSAGE '...' TYPE 'E'.
      ENDIF.
    ENDFORM.
    DESCRIBE FIELD INTO
    Note
    This statement is for internal use only.
    It cannot be used in application programs.
    Syntax
    DESCRIBE FIELD dobj INTO td.
    Effect
    All characteristics of the field f, its components , sub-components etc. are displayed in the field td (type description). td has to be of the type SYDES_DESC, defined in Type Group SYDES. Because of this, the type group SYDES must be integrated into the ABAP-program with a TYPE-POOLS statement .
    The structure SYDES_DESC has two table-type components TYPES and NAMES:
    In TYPES, the tree structure of the type belonging to f is displayed. The components of a node are stored in the table TYPES in a continuous manner. Beginning and end of the line area that represents the components are stored in TYPES-FROM and TYPES-TO. The reference to the superior node can be found in TYPES-BACK. If no superior resp. subordinate node exists, then this is marked by the value 0 (For the relevance of further components, refer to the following sections).
    The names of components, types etc. are not stored directly in TYPES. Instead, the components TYPES-IDX_... hold an index in the name table NAMES. The value 0 indicates that there is no reference to the name table.
    NAMES contains the possibly fragmented names in the component NAMES-NAME. If a name continues in the following line, this is indicated by an asterisk ('*') in the component NAMES-CONTINUE.
    The type description table (TYPES) not only stores information about the tree structure but also further information about the type of f resp. its components. This includes especially all information that can be determined using the usual additions to DESCRIBE FIELD. In detail, TYPES contains the following columns:
    IDX_NAME
    Component Name
    IDX_USER_TYPE
    Name of a user-defined type, i.e., a type that was defined through its TYPES-statement. Derived types (... TYPE A-B) and structures from the ABAP-Dictionary are not considered to be user-defined types.
    CONTEXT
    For user-defined types only: The context, in which the type is defined. Possible values are defined in the constant SYDES_CONTEXT of the type group SYDES. Please only use these constants to carry out a comparison. In detail, we distinguish between the following type contexts:
    SYDES_CONTEXT-PROGRAM: Program-global type
    SYDES_CONTEXT-FORM   : FORM-local type
    SYDES_CONTEXT-FUNCTION: FUNCTION-local type
    SYDES_CONTEXT-METHOD : METHOD-local type
    IDX_CONTEXT_NAME
    For user-defined types only:
    With a local context: The name of the FORM or FUNCTION, whose type was defined. The name of the associated program is then the first entry in the name table.
    With a global context: The name of the program in which the type was defined.
    IDX_EDIT_MASK
    Conversion routine from the ABAP-Dictionary, is in accordance with the addition EDIT MASK at simple DESCRIBE.
    IDX_HELP_ID
    Help-Id when referencing to fields from the ABAP-Dictionary
    LENGTH
    Internal length, corresponds to the addition LENGTH at simple DESCRIBE
    OUTPUT_LENGTH
    Output length, corresponds to the addition OUTPUT-LENGTH at simple DESCRIBE
    DECIMALS
    Number of decimal digits, corresponds to the addition DECIMALS at simple DESCRIBE
    TYPE
    ABAP-Type, corresponds to the addition TYPE at simple DESCRIBE
    TABLE_KIND
    A table type is stored here for the components which represent an internal table. The same values are returned as with the variant DESCRIBE TABLE itab KIND k. Components which do not represent a table get the return value set to SYDES_KIND-UNDEFINED (see type group SYDES).
    Example
    Example definition of the complex data type EMPLOYEE_STRUC:
    PROGRAM DESCTEST.
    TYPES: BEGIN OF name_struc,
             first  TYPE c LENGTH 20,
             last   TYPE c LENGTH 20,
           END OF name_struc,
           BEGIN OF absence_time_struc,
             day        TYPE d,
             from       TYPE t,
             to         TYPE t,
           END OF absence_time_struc,
           phone_number TYPE n LENGTH 20,
           BEGIN OF employee_struc,
             id         LIKE sbook-customid,
             name       TYPE name_struc,
             BEGIN OF address,
               street  TYPE c LENGTH 30,
               zipcode TYPE n LENGTH 4,
               place   TYPE c LENGTH 30,
             END OF address,
             salary_per_month TYPE p LENGTH 10 DECIMALS 3,
             absent           TYPE STANDARD TABLE OF absence_time_struc
                                   WITH NON-UNIQUE DEFAULT KEY,
             phone            TYPE STANDARD TABLE OF phone_number
                                   WITH NON-UNIQUE DEFAULT KEY,
           END OF employee_struc.
    You can determine the structure of the type EMPLOYEE_STRUC by collecting the type group SYDES as follows:
    TYPE-POOLS: sydes.
    DATA: employee TYPE employee_struc,
          td       TYPE sydes_desc.
    DESCRIBE FIELD employee INTO td.
    The following table shows a few selected columns of the type description table TD-TYPES. For a better overview, the names of the columns IDX_NAME, IDX_UERR_TYPE and IDX_EDIT_MASK have been shortened:
        |FROM| TO |BACK|NAME|UTYP|EMSK|TYPE
    |--||||||--
      1 |  2 |  7 |  0 |  0 |  2 |  0 |  v
      2 |  0 |  0 |  1 |  6 |  0 |  4 |  N
      3 |  8 |  9 |  1 |  7 |  5 |  0 |  u
      4 | 10 | 12 |  1 |  8 |  0 |  0 |  u
      5 |  0 |  0 |  1 |  9 |  0 |  0 |  P
      6 | 13 | 13 |  1 | 11 |  0 |  0 |  h
      7 | 17 | 17 |  1 | 12 |  0 |  0 |  h
      8 |  0 |  0 |  3 | 13 |  0 |  0 |  C
      9 |  0 |  0 |  3 | 14 |  0 |  0 |  C
    10 |  0 |  0 |  4 | 15 |  0 |  0 |  C
    11 |  0 |  0 |  4 | 16 |  0 |  0 |  N
    12 |  0 |  0 |  4 | 17 |  0 |  0 |  C
    13 | 14 | 16 |  6 |  0 | 18 |  0 |  u
    14 |  0 |  0 | 13 | 20 |  0 |  0 |  D
    15 |  0 |  0 | 13 | 21 |  0 |  0 |  T
    16 |  0 |  0 | 13 | 22 |  0 |  0 |  T
    17 |  0 |  0 |  7 |  0 |  0 |  0 |  N
    Please note that the entries in rows 6 and 7 represent internal tables (ABAP-Type h). There is always an entry for the corresponding row type (rows 13 and 17) to an internal table.
    The indices in the rows 5 to 7 refer to entries in the name table TD-NAMES. If you look, e.g., at row 3, you find the corresponding component name in TD-NAMES from row 7 (NAME) onward and the corresponding user type from row 5 (NAME_STRUC) onward.
    In the name table TD-NAMES you find the following entries. Note that the names SALARY_PER_MONTH and ABSENCE_TIME_STRUC are stored in two parts:
        |CONTINUE|NAME                   |CONTINUE|NAME
    |--|     -||--
      1 |        |DESCTEST            12 |        |PHONE
      2 |        |EMPLOYEE_STRUC      13 |        |FIRST
      3 |        |SBOOK-CUSTOMID      14 |        |LAST
      4 |        |==ALPHA             15 |        |STREET
      5 |        |NAME_STRUC          16 |        |ZIPCODE
      6 |        |ID                  17 |        |PLACE
      7 |        |NAME                18 |   *    |ABSENCE_TIME_ST
      8 |        |ADDRESS             19 |        |RUC
      9 |   *    |SALARY_PER_MONT     20 |        |DAY
    10 |        |H                   21 |        |FROM
    11 |        |ABSENT              22 |        |TO

  • How to get number of digits in given amount

    Hi Experts,
    How to get number of digits in given amount.
    Regards
    Mohit

    Check this :
    data: v_data1 type p decimals 3 value '12.860',
          v_char1 type char20,
          v_char2 type char20,
          v_char3 type char20,
          len type i.
    write v_data1 to v_char1.
    split v_char1 at '.' into v_char2 v_char3.
    len = strlen( v_char3 ).
    write:/ v_char2,
          / v_char3, " this holds the digit value
          / len.     " number digits

  • Number of decimals in the stock, availability tab.

    Hi,
    Dose anybody know if it is possible to change the number of decimals that appear in the availability tab, in the stock. It appears 3 decimals (as is defined in the data type).
    any clue???
    thanks for your attention
    best regards.
    Jorge Vigo

    Hi Sorin,
    thank you very much for such a clear answer.
    Regarding the question of how to give the parameter value, we did input once 25,10 and ended up in an error upon "modify application" execution. We actually had to delete that entry (Full Optimize Problem) because BPC seemed to not like the comma at all in the tblDefaults table where that value is written (by the way, we did delete it through web admin as you suggested, not directly in the table, -almost- never delete directly from the table
    If just a plain 25,10 is the appropriate value, do we need to delete that value from Web Admin once the application has been copied and processed? Should we rather not have any problem at all by inserting 25,10 in Web Admin?
    Thank you,
    Rafael

  • Again: Number Format, Decimals in calculated fields

    My customer wants to know how he can have calculated fields in his reports.
    I've found out that e.g. this works for the calculation:
    <?format-number:((SALARY) div (../../DEPTSAL));'#,##0.00'?>
    But there is no way that I can get a precision of two decimals. All given formats are ignored.
    Maybe this is an issue with the european decimal sign , (Comma).
    How is this to be fixed?
    The use of the translate function was recommended somewhere. I have no idea how to bring it together with my calculation formula.
    Thanks in advance,
    Kai
    Message was edited by:
    kai

    Hi kai,
    First you need to remove comma from your amount field then you can get your result.
    If you have any comma in your amount field then xml number format does not work.
    Look this forum:
    Re: How to indicate number percission in a template?
    Thanks
    Ravi
    Message was edited by:
    Ravi Tripathi

  • KONV-KAWRT number of decimals

    The condition base value of a condition is always stored with 2 decimals in KONV-KAWRT, regardless of the actual number of decimals which depends on the unit in KONV-KMEIN. For example, 500 G (gram) is stored as 5000.00 G because G really has 3 decimals.
    When viewing a condition in VA03 or VF03, SAP will show the condition base value with the right number of decimals.
    My question: how can I determine the actual number of decimals myself? I thought it might be in T006-ANDEC, but that's not it.

    Dear Filip,
    Try the following simple syntax:
    DATA: FLD(8) TYPE P DECIMALS 2,
    DEC TYPE P.
    DESCRIBE FIELD FLD DECIMALS DEC.
    DESCRIBE FIELD KONV-KAWRT DECIMALS DEC.
    Regards,
    Pranav.

  • How to decide inserting Queries into Workbooks

    Hi,
    I have a few doubts..pls clarify my doubts
    1. How to decide inserting Queries into workbooks (How many number of Queries will be inserting into workbooks??)
    2. Shall i use single sheet (or) Multiple sheets
    3. We are using Hierarchy...So, How to insert a Query( How to decide which row/coulmn the Query can be placed??)
    4. How to suppress Zeros and # permanently (For temporarily, i went to cell context menu--All Characteristics-Suppress zero column/Row..)
    But looking for permanent solution..
    Please Suggest me ...
    Thanks..
    Help will be greatly appreciated..
    Thanks.........

    Hi venkat,
    1.how may queries in a workbook will depend on the reporting requirement.
    2. single or multiple sheet - it is advisable to insert one query in each sheet to avoid confusion.
    3. If you are using hierarchies then it is not advisable to use then in worrkbooks, since the values in the cells would keep changing depending on the hierarchy and the level it is expanded etc.
    4. To supress zeros you can also do a setting in spro -- > SAP netweaver --> SAP Business information warehouse --> Report-relevant settings --> presenting the numeric value in the Business explorer
    Standard settings
    Under certain circumstances numeric values and texts for currencies, or units, in the Business Explorer cannot be determined uniquely. In such cases predefined texts are displayed instead of the numeric values, and currencies, or units:
    If a Division by zero arises when calculating a numeric value then this text is output.
    If a numeric value cannot be determined then this text is output (does not exist).
    If a numeric value is not calculated due to numeric overlapping then this text is output.
    If a numeric value is made up of several currencies, or units, then this text is output instead of the currency or unit (mixed currencies).
    If a user does not have authorization to display a particular numeric value for a cell in the executed query, then this text is output in the cell instead (no authorization).
    If a calculated numeric value is made up of different currencies, or units, then the numeric value can or cannot be output. If you choose mixed values then the numeric value is output. If mixed values is not active then the text is output that you entered under "mixed currencies".
    Activities
    1. Determine the texts that are to be output in the Business Explorer instead of numeric values.
    2. Decide whether numeric values, that are made up of different currencies, or units, should be output.
    If the above explanation was helpful, please assign reward points.
    Regards
    Venkata Devaraj

  • ALV column with variable number of decimals to be displayed

    Hi,
    I've an ALV where I need to display a numeric column with a variable number of decimal row-by-row, from 0 (no decimals) to 4.
    I've declared the numeric field as TYPE P DECIMALS 4.
    I've tried with DECMLFIELD in ALV catalog, and this works for 1 to n decimals, but when  I leave the field indicated in DECMLFIELD equal to 0, ALV shows the default number of decimals of the field (4 in that case).
    Any help will be very appreciated.
    Thanks.
    Jordi

    No, I didn't try EDIT_MASK.
    How should I use it to format output to display decimals or not depending on the row?
    I have 2 kinds of values, all stored in a TYPE P DECIMALS 4: Those that really are an integer (decimals should not be displayed for that ones) and the values that really have 4 decimals (which should be displayed with decimals in ALV).
    Example:
    13,0000 should be displayed as 13
    0,4567 should be displayed as 0,4567
    With EDIT_MASK could I do that?
    Thank you very much.

  • Number of decimals in an application

    Hi all,
    I need to change the number of decimals in some applications, and have been reading some threads about it. I have found some different explanations, and I would like to make sure of how to do it.
    1) What do the numbers in the parameter SIGNED_DATA_FORMAT mean? For example 25,10 means:
          a) we have 25 digits to the left of the comma and 10 to the right, like 1234567891234567891234567.1234567890
          b) we have 25 digits in total and 10 for the decimals, like 123456789123456.1234567890
    2) If the correct answer to the previous question is "b" (I think that is the correct one), 25 is the maximum amount of numbers we can have? Could we set 50,15?
    3) what is the correct way of inputting the value in the parameter (in BPC Web Admin Application parameters)? (I mean, like 25,10 or (25,10) or "25,10" or 25.10 or.....). We had a problem some time ago with this ( Full Optimize Problem ).
    4) so, to make the modification, we should first set the parameter in an application, then make a copy of the application (the new one will have the number of decimals changed), then delete the first application, right?
    Thank you very much,
    Rafael

    Hi Sorin,
    thank you very much for such a clear answer.
    Regarding the question of how to give the parameter value, we did input once 25,10 and ended up in an error upon "modify application" execution. We actually had to delete that entry (Full Optimize Problem) because BPC seemed to not like the comma at all in the tblDefaults table where that value is written (by the way, we did delete it through web admin as you suggested, not directly in the table, -almost- never delete directly from the table
    If just a plain 25,10 is the appropriate value, do we need to delete that value from Web Admin once the application has been copied and processed? Should we rather not have any problem at all by inserting 25,10 in Web Admin?
    Thank you,
    Rafael

  • How to Plot number and string in one row (data logger counter) ?

    hi all i made data log quantity using Digital Counter via modbus to monitoring quantity and reject that has and Name Operator, Machine and Part Number.
    i have problem about plot the number & string in one row, as shown on the picture below :
    how to move that string on one row ? i attach my vi.
    Thanks~
    Attachments:
    MODBUS LIB Counter.vi ‏39 KB

    Duplicate and answered - http://forums.ni.com/t5/LabVIEW/How-to-Plot-number-and-string-in-one-row-data-logger-counter-via/m-p...

  • CRM Web UI :- How to Control number of session of Web UI for a user

    Hello Experts,
    We do have very specific requirement which SAP doesn`t recommend in terms of multi-sessioning for a user.So we are little worried upon the challeges.Could you please share your ideas/Experience on following?
    1.How to Control number of Internet explorer session for the web UI (may be 2 or 3).?
      Though SAP doesn`t recommned more than one but our client requires 2 or more than that but we need to fix it either 
      2 or 3.
      So we are looking for specific setting for this.
    2.What are the challenges we need to face if we implement option 1?
    3.Specially in interaction record management
        a. Is there chance of loosing the data if agent has opened more than two session.
        b. In which session interaction record data will get stored,the one on which agent picked up the call or in the latest 
            one?
    Please let me know if I am not clear enough on any point.
    Thanks in advance,
    Shailendra Tolambiya

    Hi Shailendra,
    The following wiki page might be useful in this respect:
    http://wiki.sdn.sap.com/wiki/x/gxdKDQ
    Best Regards,
    Shiromani

Maybe you are looking for

  • Java.io.Reader - java.io.InputStream

    Hi! Is there a way to wrap a java.io.Reader into an java.io.InputStream (like java.io.InputStreamReader does but in the other direction)? I found now class doing this job (deduced from java.io.InputStream, taking an java.io.Reader as Constructor Para

  • My MacBook screen won't stay lit

    I came in to find that my cat had knocked my MacBook on the floor and now I can't get my screen to stay lit. It will flicker for a split second when I run my finger across the trackpad and then it goes dark.

  • Iphone 4 Lost all Data after updating

    Hi there.. i got headache reading everywhere to find a solution to my problem, and didn't find any useful tips so far, i haven't slept for the past 24 hours because of this.. last day i did an update to my itunes to the latest version, and upgraded m

  • I get a dump of HTML instead of a POPUPKEYVALUE contents while running app.

    Hi, Many times I get a dump of HTML instead of a POPUPKEYVALUE contents while running the app. If I reload the POPUP it fills with the choices as it should have. I have had no complaints from Users though so I think it is just dev area. HTTP/1.1 200

  • Coverflow for video and podcasts

    Has it been discussed about implementing coverflow for video and podcasts? This would make it so much easier to navigate and also help organize the files on the itouch and iphone. How serious is apple about implementing these, Im dying to get this fo