How to restrict the decimal place of a floating point number?

Hi,
Here is my code:
public void TwoDecimal(double u){
     String w = Double.toString(u);
     int c = w.length();
     System.out.println(c);
     if (c <= 5)
        double a = Double.parseDouble(w);
        System.out.println(a);
     else
        System.out.println("Invalid input!");
  }I want to show a floating point number which has 2 digits and 2 decimal places, e.g. 45.82, 29.67. This number is input by user and passed as a parameter.
For those case like the above sample floating point numbers, it can display the proper value of 'c'. e.g. 45.67 will display 5.
However, when I passed 99999, it will show 7; 9999 will return 6, not 5.
So, if the user does not input the '.', does it append 2 implicit chars to it? i.e. 99999.0 and 9999.0. So, that's why it returned 7 and 6 for the length of the string respectively.
How can I fix it?
and
Does it has better algorithm?
Pls advise.
gogo

When dealing with a known precision, in your case hundredths, it is often a good idea to use an integer type and add in the decimals on printing only. This is often the case in banking systems. Almost all of them use integer types, (read long) in pennies to store monitary values. Ever seen someone type in a value for a credit card machine? For something like $20 they press.. "2" "0" "0" "0" The machine knows the lowest denomonation in a cent, so it knows where to put the decimal place. I suggest you do something like this. It also helps to avoid base 2 round off errors.
-Spinoza

Similar Messages

  • How to restrict the decimal entry on dynamic table in adf 11 .6

    Hi All,
      JDev version 11.6
      I have a usecase based on dynamic VO. How to restrict the decimal numbers on table columns . When user enter the decimal number .I have to show error message.
      In order to achieve above requirement .I have added value change listener on table column .its not working as expected
    <af:table rows="#{bindings.EmployeeDynamicVO.rangeSize}"
                      fetchSize="#{bindings.EmployeeDynamicVO.rangeSize}"
                      emptyText="#{bindings.EmployeeDynamicVO.viewable ? 'No data to display.' : 'Access Denied.'}"
                      var="row" rowBandingInterval="0"
                      value="#{bindings.EmployeeDynamicVO.collectionModel}"
                      selectedRowKeys="#{bindings.EmployeeDynamicVO.collectionModel.selectedRow}"
                      selectionListener="#{bindings.EmployeeDynamicVO.collectionModel.makeCurrent}"
                      rowSelection="single" id="t1"
                      styleClass="AFStretchWidth" autoHeightRows="-1"
                      columnStretching="last" contentDelivery="immediate" >
              <af:forEach items="#{bindings.EmployeeDynamicVO.attributeDefs}"
                          var="def">
                <af:column headerText="#{bindings.EmployeeDynamicVO.labels[def.name]}"
                           sortProperty="#{def.name}" id="c1">
                  <af:inputText value="#{row[def.name]}" id="ot1"
                                valueChangeListener="#{backingBeanScope.EmployeeBean.validateINputs}"
                                autoSubmit="true">
                    </af:inputText>
                  <af:outputText value="#{row[def.name]}" id="ot6"
                                 visible="#{def.name eq 'Dummy'}"/>
                </af:column>
              </af:forEach>
            </af:table>
    So appriciate if any alternatives on above usecase. Thanks in advance

    HI
    Expected :as soon as user enter the decimal values in table column , it should throw the error message in new small new window
    Getting the value change listener and validating , but its working only tab out (Because VO is dynamic )
    please suggest us any reg expression and Validators to achieve the above scenario ?

  • Without to change the setting.how to set the decimal place to 7 for an UDF.

    Without to change the setting, how to set the decimal place to 7 for an UDF?

    Hi
    Once you create a UDF it will automatically be binded to the data source of data type that you gave at the time of creating UDF.
    So i think you can not set the decimal places without changing the setting in display parameters.
    i am not sure whether it will work or not one thing you can try is that create it as a alphanumeric data type and convert your decimal value to sting and then assign it to UDF,While retrieving for any manipulation you convert it as decimal.
    Hope it helps you
    Regards
    Vishnu

  • How to change the decimal places in the value axis of a chart in WAD?

    Hello,
    The key figure in my chart has 2 decimal places and I want the value axis to show the same. How to do that?
    Thanks in advance, Nathalie

    Hi,
    change the Format property of the ValueAxis-Line to 0.00
    Then the axis displays its values including two digits after the decimal.
    Regards, Kai

  • How to find the decimal portion of a FLOAT

    Hi,
    I have a columnX with datetype of FLOAT with a value of 61827.52, 60428.99, and etc.
    The number portion represent a date.
    How to convert it from 61827.52 to 61827 without round off issue
    and use 61827 to convert to date?
    thanks.

    Buga wrote:
    Prazy did show you the first half, howvever the second part was only a joke right?hehe.. Great spot..
    Just a wild guess, it may be 27-08-1961. *{:-)                                                                                                                                                                                                                                                                                                                                                                                                   

  • How 2 extract 2 decimal places from a float variable

    Hiya,
    I have a float variable say x with a value 10.56879, how do i extract 56 without rounding it up. I want to store 56 in an integer variable after extracting it from float.
    Cheers
    Deepak

    This works when f is positive,
    float f = 10.56879f;
    int i = Math.round((float)Math.floor(((f - (float)Math.floor(f))*100.0f)));
    System.out.println(i);

  • How to restrict the changes in Relesed PO?.

    Hi all,
    How to restrict the users to make a changes in the Released PO?. User should make the changes only if it is unreleased by the respective codes.
    1. Is there any user parameters like functional authorisation?
    2. I have already suggested two solutions to the clients that
        1. To restrict the authorisation of TCodes ME22n at the user level, but it's not a suitable solution, if user want to make any changes before releasing, then system is not allow to do the changes.
        2. I have made release indicator as a 1 - not changeable if it is released, in release strategy settings. But the system is not allowing the all the users including release codes to make the changes?.
    If there is any solution, please reply immediately.
    with regards,
    Raja.

    hi,
    if u set release indicator 1, after release is taken place, for any changes, u need to revoke the release. and then change the PO.
    even u cant directly block the changes to already released PO, because, in future if at all qty or some changes is required to change, it should allow u to change!

  • How to restrict the delivery quantity not more than target quantity?

    Dear Gurus,
    How to restrict the delivery quantity not more than target quantity in a scheduling agreement? I think there are 2 methods.
    1. I found that setting 0 in Overdelivery Tolerance Limit in Info Record is not effective. Why?
    2. I want to set E for the message but can't find the place. The message is generated when entering and saving quantity as delivery quantity that is larger than target quantity. How can I set E to a message (067, as I remember)
    Any other effective method? Please advice. Thanks.
    Regards,
    David

    Dear all,
    It is not OK after checking everywhere you mentioned. I tested in 2 clients. In the development enviroment client, it works whatever E or W. In test enviroment, it does not work (meassge is W).
    I think there must be somewhere besides of those you menetioned.
    I notes that SAP help for the overdelivery tollerance setting of scheduling agreement: 
    Overdelivery Tolerance Limit
    Percentage (based on the order quantity) up to which an overdelivery of this item will be accepted.
    Dependencies
    If you have set the indicator in the Partial delivery/Item field to 'D' (partial delivery allowed), this takes priority. It makes no sense to define a tolerance limit for overdelivery in such case.
    Where can I see: 'the indicator in the Partial delivery/Item field to 'D' (partial delivery allowed)'? I want to check it.
    Pls help! Thanks.
    Regards,
    David

  • How to restrict the upload file size in me21n/me22n/me23n?

    Hi Guru's,
    I have a requirement to restrict the user from attaching a local file more than 20MB in Purchase Order.
    In standard SAP system, the user can attach a file of any size in PO. How to restrict the size of the file?
    I have no clue how to achieve this? Any kind of help would be great...
    Thanks in Advance...
    Regards,
    Satyam

    Hi Guru's,
    The file size is now restricted in function GUI_UPLOAD. But this function module is used at many places. I want to restrict it only for Tcode: ME22n and ME23n.
    I thought of restricting it by sy-tcode field but sy-tcode value  is not passed to this function module in the run time.
    Could anyone help me on this how to restrict it for the above mentioned tcodes??
    Regards,
    Satyam

  • How do you set the decimal precision of a float?

    Hello,
    I am new to Java and have run into a problem. I am trying to truncate an array of floats and save them to a file. I want to save two decimal places with 0's ie: 0 as 0.00
    For example:
    I have a number 0.9772128 and I want to convert it and store it as 0.98, the following code seems to truncate it but there is a problem.
    float d = output_Weights;
    d = Math.round(d * 100) / 100.0;
    some of my numbers come out as .1 instead of .10 and I can't seem to figure out how to add the 0's on the end of them.
    Does anyone have any suggestions or a better way of getting the two decimal precision?
    Thanks in advance for any help you might be able to offer.

    And if you want to set the decimal precision when you convert the floating point number to text (which is what you are talking about when you say it ends with .1 instead of .10), you use a DecimalFormat object to do that.
    (By the way, isn't there supposed to be an apostrophe in Arc'teryx?)

  • The decimal place is wrong in GR55

    Dear Expert:
    We are using currency JPY
    We now creating a new report using report painter, but unfortunately the decimal place is wrong,
    the result is only one percentage of the real amount, how can I get this issue solved?
    notice that we are using report painter, not ABAP programming, so function module BAPI_CURRENCY_CONV_TO_INTERNAL
    is not applicable.

    Dear Lu Meng
    I was reading your question which seems not answered at all.
    I have EXACTLY your same issue.
    In ECC using a FAGLFLEXT Report Painter.
    My zero decimal currencies such as HUF and JPY are showing in the report, with decimals, thus are factor of 100 too small. Even changing layout deimcals, etc has NO EFFECT.
    Did you solve this sissue? OSS has nothing either?
    Thanks for any assistance.
    Richard

  • Changing the Decimal places in the currency

    Hi all
    we are using the currecy SAR. Decimal places was set to 4, now that they want to revert back to 2 decimal places. i understand that by doing so they would be inconsistencies in the data allready recorded. how to avoid that?
    is there any programmes / reports that would fix such inconsistencies?
    any OSS notes?
    thanks and regards
    gkk

    HI,
    You should NOT change the decimal places in a productive system.
    If you would do, the correction of the posted documents afterwards would be a remote consulting issue. Which you have to pay for SAP.
    You see, all posting you have done until now, would get displayed in a wrong way, and the new posting wouldn't compare to the others.
    Please check the note 137626 describes this.
    If you really need to change the decimals, you should create a new currency type, for example your current is SAR, and now you should create a SA2. Then you should enter new rations and exchange rates for it, and work with the new one.
    Also if you want to set the decimals to two digits from four, youshould not enter an entry in the OY04(TCURX).
    In this table you can only enter a value, that discriminate from 2 decimals. If there is no entry in the table, it means the currency has two decimals.
    Please assign points if it useful.
    Regards
    Ravinagh Boni

  • How we can increase decimal places in Sales Order for Qty

    Hi,
    In Sales Order qty field now its 3 decimal places for MON unit of measure but we want 4. how we can increase decimal places.
    Thanks in advance
    Thanks & Regards,
    PM

    To elaborate better.
    Again, use Tcode CUNI - Unit of measurement : Initial Screen.
    At initial screen, choose TIME from the list (where by default AAAADL- no dimensions is there).
    And click on UNIT OF MEASUREMENT button.
    In that you will find MON - Month.
    There go for details by selecting MON or select MON and press F5 from Key board.
    For MON unit maintain following parameter as per your requirement:
    -Number of decimal places for number display
    Use - This parameter determines the number of decimal places with which this measurement unit is displayed.
    -Base ten exponent for floating-point display
    Use - This exponent determines how the values for this measurement unit are formatted as floating point numbers.
    Examples - If the exponent is 3, the floating point numbers have the format xxx.xxxxE3.
    And deselect commercial meas. unit in application parameters section.
    I would suggest instead of changing standard settings of MON, you create ZMON in TIME dimension.
    Thanks & Regards
    JP

  • Removing the decimal places of currency field

    Hi Gurus,
    I have a currency type field ( to be more specific a field like BSEG-WRBTR) .
    How do i eliminate the decimal places for this field.
    ie if the value is 345678.91, i need to make it 345678.
    Is there a standard keyword or something for this?
    Points will be given to all the helpful answers.
    Thanks,
    Nobin.

    You can use the FLOOR function to get the largest integer value without decimal.
    Like:
    DATA: W_RESULT TYPE I.
    W_RESULT = FLOOR( P_AMT ).
    Regards,
    Naimesh Patel

  • How to restrict the job start conditions (only "Immediate" type) ?

    Hi,
    We allow our users to schedule and execute in background mode transactions (example IP19, IW38). We gave them for that authorizations (object S_BTCH_JOB with LIST, PROT, RELE and SHOW - objetct S_PROGRAM with BTCSUBMIT).
    We would like that users can schedule and execute their jobs only with the u201CImmediateu201D job start condition (in the Start Time screen for the type of start condition : Immediate, Date/Time, After job, After event, or At operation mode).
    Another solution: prohibit the scheduling and the execution background job in a certain time interval ...
    How can restrict the job start conditions ?
    Thank you.
    Patrice.

    Hi Jan,
    Yes, sa38 makes it possible indeed to execute in background into immediate mode a job but
    the user have to know the name of the program to be carried out ...
    The user knows only the name of these transactions trade. For example, IW38.
    In the menu of this transaction, SAP gives the possibility to execute in background :
    Program --> Execute in Background --> display of Start Time screen for the type of start condition :
    Immediate, Date/Time, After job, After event, or At operation mode).
    It is at this time there that we want that the user can only choose the "immediate" mode.
    We must thus prohibit the other choices (Date/Time, After job, After event, or At operation mode) ... and
    and we don't know how to restrict these other options in this screen "Start Time screen for the type of start condition".
    Thank you.
    By.

Maybe you are looking for

  • CD Drive no longer reading.

    About a month ago, my CD/DVD drive stopped working. I could hear the disc spin, and the laptop would make a noise like it usually did, but after that - nothing. The drive wouldn't even show up on the Computer folder with the rest of my hardware. I pe

  • Stock Transfer from Bonded WH to Depot (Excise)

    Hi All, We have a business scenario of bonded warehouse where material is imported. In SAP we are following the below process. a. Create Import PO without any duty > GRN > MIRO (Vendor Payment) b. Create STO with bonded warehouse as our supplying pla

  • UCCX send entered digits to CAD display

    Hi, I'm trying to get a set of numbers (that will be entered by the caller) to show up in the enterprise data fields in CAD. Scenario would be that the caller would have to enter their customer number (7 digits) and when the call gets put through to

  • The Project implementation

    Hi Everybody, I am working with Implementation project for the first time at client place so i have to handle all the things ... so let me know the procedure how to proceed .... first is Blue prints ..... if any body is having blue prints format pls

  • Where the session begin when user login

    Hi all, Just want a detail understanding of where the session starts when user login in ATG application (handle login), and where the session ends (handlelogout) thanks and regards 333