I need the decimal part of a double...

...but I can't find a 'method' in the api to do this. Is there one?
I would rather avoid writing one myself.
Also, how can I set the precision of a float? I glanced at BigInteger but it seems to be for output only.
Thanks,
Jeff

what if I need to compare the thousands place ofthe
decimal part?Then you can either do it arithmetically, similar to
what itchyscratchy showed, or you can format it as a
string and compare the third character to the left of
the decimal.Oops. Fourth character.

Similar Messages

  • Separate the int and decimal parts of a double var

    Hi,
    I would like to know how can I obtain the int part and decimal of a double var.
    Example:
    2.3455
    int -->2
    decimal--->3455
    Also I would like to know how I can specify the precision of the decimal part. For example: 3455 if want a 2 decimal precision--> 34
    Regards and thanks with anticipation.

    Hi all,
    I too have a way to this solve this.
    1. Convert the double into a string.
    2. Split it by . symbol, which will produce an array of two elements.( First one is integer part, another one is decimal part)
    3. Now we can easily do type casting and get two variables.
    Example:
    double base = 2.5689;
    String str = Double.toString(base);
    String[] out = null;
    out = str.split(".");
    int a = Integer.parseInt(out[0]);
    double b = Double.parseDouble(out[1]);Thanks
    Ram

  • How to read the decimal portion of a double number? (using scanner method)

    hello Java pros....
    I need to read the integer and decimal part of a double number, one independently of the other.
    I must be able to assign the integer part to a variable, and the decimal part to a different variable.
    Is there a method that does what I need directly after reading the initial value (double) ?
    or, should I include the condition to read the decimal point somehow?
    the initial value will be input from the console using a scanner method.
    lets say the number I have is 123.345
    I must be able to separate 123 from 345 and use them independently.
    thank you all!!
    al

    The scanner should read in the user input as a string, so you have "123.456". Do something like the following:
    String   doubleNumber             = "123.456";
    String[] numberParts              = doubleNumber.split("\\.");
    int       wholeNumberPortion       = Integer.parseInt(numberParts[0]);
    int       fractionalPortion        = Integer.parseInt(numberParts[1]);
    System.out.println(wholeNumberPortion  + "." +  fractionalPortion);

  • How to fix the decimal part(round) i.e. fix the size of float.

    how to fix the decimal part(round) i.e. fix the size of float.

    You can use BigDecimal to round of your number.
    float f = 5.678f;
    f = new BigDecimal(f).setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();If you just want to display the float with a certain number of decimals, you can use java.text.DecimalFormat
    DecimalFormat df = new DecumalFormat("0.00"); // two decimals
    float f = 5.678f;
    System.out.println(df.format(f)); // should show up as 5.68

  • Take the decimal part of a number in mapping

    Hi,
    If I receive a value as 123,456 and I need to map the integer number to FIELD1 and the decimal number to FIELD2 as this:
    FIELD1=123
    FIELD2=456
    Can I do this without using UDFs?

    Hi,
            I don't think this is possible with standard text functions, as inputs to substring function are constants. You definitely need an UDF here.
    String splitNumber(String s,int part,Container container)
              String a[]=new String[2];
              a[0]=a[1]="";
              char decimalSeparetor=',';
              try
                   int i=0,j=0,l;
                   for(l=s.length();i<l && s.charAt(i)!=decimalSeparetor;++i)
                        a[j]=a[j]+s.charAt(i);
                   for(j=1,i=i+1;i<l;++i)
                        a[j]=a[j]+s.charAt(i);
              catch(Exception e)
                   e.printStackTrace();
              return a[part];
    The UDF has two inputs as shown below
    113,567 -------->splitNumber("113,567",0)    ---------->   113 (output)----->FIELD1
    113,567--------->splitNumber("113,567",1)   ------------> 567 (output)------>FIELD2
    113567---------->splitNumber("113567",0)----------------->113567 (output)-------->FIELD1
    113567---------->splitNumber("113567",1)-----------------> no output ------>FIELD2
    The value of integer part (to be supplied as constants) decides which whether you need the part of number before(0) the decimal separetor or after (1).
    regards
    Anupam

  • Number field not displaying the decimal part

    Hi,
    In a VO I've an attribute which is of type Number.
    I've set the precision & scale for the attribute as 16,4
    Even though the value in the database is having decimal part still in the UI it is just displaying the integer part.

    I've not generated the VO RowImpl file.
    The problem got solved by setting the format type in the control hints of that particular attribute of the VO.

  • Taking the whole part of a double

    Hi all,
    I have a double value...
    double res = (xIntValue/yIntValue);
    But I only wnat to output the whole part of the result, e.g
    res = 7 / 2 = 3.5
    System.out.println(3)
    I would appreciate any help.

    Cast the double to int before outputtingNo, don't do this. It's a quite inappropriate use of
    an int cast. It also breaks for numbers >
    Integer.MAX_VALUE.
    Use java.lang.Math.floor().
    Sylvia.
    double res = (xIntValue/yIntValue);Sorry, I assumed deviding two integers would create a third integer.

  • Fix the integer part in a decimal numer

    i copy the following code from this forum
    import java.awt.*;
    import java.text.*;
    import javax.swing.*;
    import javax.swing.text.*;
    public class Decimal1
      public static void main(String[] args)
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setSize(200,130);
        f.setLocation(400,300);
        JPanel panel = new JPanel();
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
        f.getContentPane().add(panel);
        DecimalFormat df = new DecimalFormat("0.00");   
        NumberFormatter nfr= new NumberFormatter(df);
        nfr.setAllowsInvalid(false);
        JFormattedTextField ftf = new JFormattedTextField(nfr);
        JLabel lFtf = new JLabel("JFormattedTextField");
        JLabel lTf = new JLabel("JTextField");
        JTextField tf = new JTextField(8);
        panel.add(lFtf);
        panel.add(ftf);
        panel.add(lTf);
        panel.add(tf);
        f.setVisible(true);
    }i want the user to input the price (the format "99999.99", the integer part is less than 5 digits. the decimal part is fixed to 2 digits)
    for example 56.45, 0.67 12345.99 , 88888.12 are accepted.
    if the integer part is more than 5 is not allowed.
    for example 123456.45, 651433.44
    i try it with Document, buy it cannot work together.
    how can i to solve it?
    thank you!

    You might want to start looking at [url http://forum.java.sun.com/thread.jspa?threadID=5164412&messageID=9629730#9629730]the threads you've previously started on the topic.

  • Using a Bind Variable in the FROM part of a SQL Statement?

    Hello Everyone,
    I have a problem, I am trying to run an SQL statement. However I need the FROM part of the SQL statement to be a bind variable. This is because the end user will need to select between 2 database views.
    I have tried this:
    select CON_ID from :P23_DB_NAME where CON_LEGACY_ID=:P23_CONLEG_NO
    I had no luck. The error i got was,
    "+Query cannot be parsed within the Builder. If you believe your query is
    syntactically correct, check the ''generic columns'' checkbox below the
    region source to proceed without parsing.
    ORA-00903: invalid table name+"
    Which makes sence, but now I am a bit stuck.
    Does anyone have any ideas as to get around this problem?
    Thanks in Advance.
    -N.S.N.O.

    The example I gave you is quite simple. You need to take some time to study it to see where you need be carefull what you put where. Now, your example of course doesn't work becaues you have several errors. This will work for you:
    DECLARE
       x   VARCHAR2 (4000);
    BEGIN
       x := x || 'SELECT CON_ID FROM ';
       x := x || :p23_db_name;
       x := x || ' WHERE CON_LEGACY_ID = ' || :p23_conleg_no;
       RETURN (x);
    END;Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

  • CLIENT_HOST the (body part) to be multi line

    Dear All,
    Am using Oracle Developer Suite 10g "Form Builder"
    I am using the following Code:
    CLIENT_HOST('rundll32.exe url.dll, FileProtocolHandler "mailto:xx.xx@com?subject=mysubject&body=mybody"');
    I need the (body part) to be multi line
    Example:
    -- Start example --
    Dear Sir,
    Kindly find the following number ----- for your information
    Best Regards
    -- End example --
    Can anyone help me
    Best Regards
    Adel Hafez

    Have you tried creating a variable for the body and using chr(10) or chr(13) to do the multiline?.
    i.e.
    vc_body :=
    "Dear Sir," || chr(10) ||
    "Kindly find the following number" ||chr(10) ||
    "--------------------------------------------------------------------------------" || chr(10) ||
    " for your information" || chr(10)
    "Best Regards" ;
    Then in your client_host you just concatenate the variable.
    CLIENT_HOST('rundll32.exe url.dll, FileProtocolHandler "mailto:xx.xx@com?subject=mysubject&body=" || vc_body);
    Edited by: Rodolfo Ferrari on Jun 17, 2009 4:00 PM

  • Project Server 2010: Is there any way to export to excel the Graph part of a view?

    We need the graphical part of a project center view in a file, is there any way to export this to excel?
    Thanks in advance.

    Hi EPM Quest,
    Unfortunately the Gantt chart of the project center views cannot be exported as is in Excel.
    But based on projects data, you can build a Gantt chart in Excel. See Office article below:
    http://office.microsoft.com/en-us/excel-help/create-a-gantt-chart-in-excel-HA001034605.aspx
    Hope this helps.
    Guillaume Rouyre - MBA, MCP, MCTS

  • I have a dv7 3165 and i need a hp part

    i have a hp dv7 3165 intel board and i need the hp part # for the heatsink

    Hi:
    Enter the product # in the applicable box at the link below and you will be directed to a listing of all the parts for your notebook that HP has replacements for, with part numbers.
    http://partsurfer.hp.com/
    The product number can be found on the same sticker as the serial number.

  • SPELL_AMOUNT : doesnt give the wordings for the decimals part.

    Dear  all
    SPELL_AMOUNT : doesnt give the wordings for the decimals part. i m using INR currency.
    Help plz
    Thnx
    Moni

    Hi  moni ,
      the function does give the wording of the decimal part , the structure which stores the result has two fields word and decword. Decword stores the wording for the decimal part.
    e.g. if you enter 10.50 INR as the input , the output is
    Word     --> TEN
    Decword  --> FIFTY.
    Regards
    Arun

  • How can I get decimal part of a number?

    Hello!
    If a Have a decimal number, I want to get the decimal part.
    Example ( 33.455 should return 455)
    Thanks!
    Edited by: fvilaca on Mar 11, 2009 6:32 PM

    Hi,
    I don't understand you (my solution and OrionNet's work fine):
    Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
    Connected as hr
    SQL>
    SQL> with data as(
      2  select 3.56 as val from dual)
      3  select to_number(regexp_replace(to_char(val), '^[0-9]+\.', '')) from data;
    TO_NUMBER(REGEXP_REPLACE(TO_CH
                                56
    SQL>
    SQL> SELECT   TO_NUMBER (SUBSTR ('3.56', INSTR ('3.56',
      2                                               '.',
      3                                               1,
      4                                               1)
      5                                        + 1)) mydecimal
      6    FROM   DUAL;
    MYDECIMAL
            56
    SQL> Regards,

  • HT204365 Hi  I wonder if you could please assist me. I tried the online 'contact us" I  chose my iPad - but when I need to chose the second part - it does not give  me any options - hence I cannot go further?   My kindle does not want to open on my iPad.

    Hi
    I wonder if you could please assist me. I tried the online 'contact us" I
    chose my iPad - but when I need to chose the second part - it does not give
    me any options - hence I cannot go further?
    My kindle does not want to open on my iPad. When I touch it - a grey screen
    with kindle written in the middle appear for a few seconds. Then goes away.
    I have restarted the iPad - still the same? What else can I do?
    Thanks
    Maryna

    Judging by the reviews of the current version of the Kindle app you aren't the only one haveing problems with it - it looks like Amazon need to fix something with the app.
    Have you tried closing the Kindle app via the iPad's multitasking bar and seeing if it works when you re-open it ? Double-click the home button to open the taskbar, and then swipe or drag the Kindle app's screen from there up and off the top of the screen to close it, and click the home button to close the taskbar.
    You could also try deleting the app and redownloading it via the Purchased tab in the App Store app on it (you will then need to redownload your books in the app, assuming that it opens).

Maybe you are looking for