Returns the integer part of a real number

Hello,
I need to know an integer value as part of a real number, like this:
double a = 0;
double x = 0;
x = 1500.00;
a = (x / 1000);
now "a" must be equal to 1.
Pascal has a function INT (a = INT(x/1000)), and what about java ?
Thanks for help,
guido

Hello,
I need to know an integer value as part of a real
number, like this:
double a = 0;
double x = 0;
x = 1500.00;
a = (x / 1000);
now "a" must be equal to 1.
Pascal has a function INT (a = INT(x/1000)), and what
about java ? It is almost the same thing.
double d = 1.5;
int i = (int) d;

Similar Messages

  • 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.

  • Getting the integer part of a float?

    This sure is a simple problem, but i couldn't find an appropriate methode or class so i just like to aks you, wheter you have an idea:^
    how do i get the integer part of a float? i mean, how do i get the "14" from the float "14.45698"?

    Sounds like you need to explicitly cast it to an integer, like this:
    double      number1 = 14.45698;
              int     number2 = 0;
              number2 = (int) number1;
    Hope this helps.

  • Why do I need to return the old part, if I purchase a new part?

    Well, I had a problem with my motherboard, and got it replaced by an on-site tech HP sent me.
    The notebook is well out of warranty, aand I paid for the new motherboard+labor.
    However, when the tech showed up, he said he won't replace the motherboard unless I give him the old motherboard. He went on to say that this was the "company policy" and he won't let me keep any old part even if I pay for the new part.
    I was too tired t o argue with him, and he replaced the motherboard, and took away the old motherboard.
    On second thought, this is pretty absurd.
    It's like HP telling me "If you purchase a new HP notebook, you'll have to return your old HP notebook back to us".
    It would make sense if I was getting a free replacement and the notebook was under warranty. It doesn't make any sense when the notebook is out of warranty and I'm paying for the replacement part.
    Think of it, when I purchased the notebook, i obviously paid for the motherboard that came with the notebook. So why does HP get to take it away from me?
    If I purchase a new battery from HP store instead of amazon, do I need to return my old battery to HP?
    If I purchase a new keyboard from the HP store, do I need to return my old keyboard?
    I can give you the case number if you want.
    Honestly, if this is the "company policy", I won't ever bother with another HP product again.
    This question was solved.
    View Solution.

    HP only has new motherboards. They sell the bad ones into the Chinese market and they show up on eBay and similar places. You have a new motherboard. If you can tell us the part number of what you bought we can tell you the "full" price and the "exchange" price of the part. They should definitely explain the options to you but I think they likely assume you want the lower exchange price. 

  • Want to truncate the integer part of a number

    hi gurus
    My requirement is round off a decimal value
    in such a fashion that
    if is 12.7767898 then convert to 12.50
    again if it is 12.498989 convert to 12.50.
    please help
    Thanks in advance

    You could do something like this:
    DATA: number(16) TYPE P DECIMALS 4.
               whole_part(16) TYPE C,
               remainder(4) TYPE C,
               value(20) TYPE C.
    MOVE number TO value.
    SPLIT value AT ',' INTO whole_part remainder.
    Then, examine the remainder:
    IF remainder(1) GE '5'.
      remainder = '5000'.
    ELSE.
    * do something else
    ENDIF.
    CONCATENATE whole_part ',' remainder INTO value.
    In your data display method, display this character string (value) instead of the numerical value (number).
    This is a bit unfortunate because you have to type cast your value to string, but it works well enough. Just make sure you don't have any arithmetical operations on this newly created data field because you will get an exception.
    Also, please note that this is not the complete solution, but only to give you an idea.
    Regards,
    SD

  • 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.

  • 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 can I make imaginary number with known real number

    I need to compose pure imeginary number in my programming(ie. chamge the real number to be the imeginary part of a complex number). But The functions I found can only change the real number to be the real part of a ccomplex number. How can I compose or make imaginary number with known real number? And Can LABVIEW cope with computation of complex numbers directly?

    Use the Re/Im To Complex function, which is found on the Functions >> Numeric >> Complex palette.
    Good luck,
    Jim

  • Fixed point division on FPGA doesn't show the fraction part

    Hi,
    I'm trying to normalize a fixed-point complex vector. My problem is in the part of fixed point division. Assuming I am dividing x by y (x/y), then I multiply first x by 2^26 and y by 2^9 then divide both of them using high throughput function then multiply the result by 2^-17 and here the problem appears. The result is zero, and the fraction part doesn't appear. My question is: does the "scale by power of 2" block discards the fraction part and only keeps the integer part, even if the input is a fixed point input with fraction part of 20 bits length? If so then how can I get the result of dividing a number by a bigger one? I mnean how can I display a result < 1? If not, then why isn't the fraction part displayed? The numbers I used as an example are: x=10, y=182.
    The indicator is adjusted to have 64 bit word length and 44 integer length. I also write this data into a memory element and then read it through a FIFO to transfer it to the RT vi. Both of the memory and the FIFO are configured with the same word and integer lengths above. I am using 7965R series FPGA.
    Thanks in advance.

    It's worth noting that I tried this same procedure on RT vi itself and the fraction part was displayed.

  • Integer part only

    Hi everybody,
    I'm a brand new user of Labview (v 2009). I try to save some data from my electrometer (Keithley 617) in an array (time and electric current). And it works, I can see these data in a text file, with the time on the left, and on the right the value of the current. The issue is that I can only record the integer part. The current I try to record is something like 10E-12 A. So if I don't multiply the result by a constant of 10E15 for example, the result would be 0 instead of 0.00...004658 A. And it is the same for the time. I can see 1, 1, 1, 2, 2, 3, 3 instead of 1.034, 1.45, 1.89, 2.36, 2.98, 3.48, 3.95 for example. I've try to change the format, but it doesn't solve this problem of the integer part. I'd like to see the whole number (integer and decimal parts). Attached, please find my program. Also I attached 2 files. test01 is what I'd like to record, and test02 is what I currently record. Could you help me please ?
    Thank you !
    PS : I try to expose as best as I can my problem, I'm French...
    Solved!
    Go to Solution.
    Attachments:
    Keithley 617a Yang.vi ‏27 KB
    test01.txt ‏3 KB
    test02.txt ‏1 KB

    Ok I think I found a solution. A double precision float "DBL" was missing just before the "measurement" part. I attach you my program and the results.
    Thank you for your help !!
    Thomas.
    Attachments:
    Keithley 617b Yang.vi ‏26 KB
    test02.txt ‏1 KB

  • How to return a integer from Userdefined function????

    Hi All,
    I have an Userdefined funtion which is getting  an integer value from a RFC call. Now I want to pass this int value to a target field of type int. The problem I am facing is Userdefined function can only return String value and I have tried the Container also, but no result.
    Any views on how to handles this issue
    Regards,
    Raks

    Raks,
    just return the integer as a string. There should be no problem. Use:
    return String.valueOf(a);
    Regards,
    Henrique.

  • Get integer part of a double type value.

    double dblVal=150.50;
    how will i get the integer part only of variable dblVal?
    i want to get the 150 only. please help.
    killuasoft

    Why would you want to do this? This can overflow your
    int for sufficiently large double values, even when
    using a long instead of an int.Maybe he previously did a range check or otherwise knows the range of possible values.

  • 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

  • Coding - returning the number of characters in a text box.

    I am in the process of creating a cell phone simulation/animation in Edge Animate CC for use in a Captivate course. Basically, when a user clicks on number buttons on the virtual keypad, it displays the numbers in a text box , just like an actual cell phone would display the phone number on the screen as a caller is dialing. So, the user would click seven buttons and a seven-digit phone number appears on the virtual phone screen.  This part of my animation works great and all seven digits appear, but I would like to modify the code so that a hyphen appears after the third button clicked. This way, the output better resembles an actual phone number instead of just a string of seven digits.
    Here is an example of the code I currently have assigned to the #2 button on the virtual keypad:
    var text = sym.$("PhoneNum").html();
    text = text + 2;
    sym.$("PhoneNum").html(text);
    PhoneNum is the name of my text box on the stage where the digits appear as each keypad button is clicked.
    In order to incorporate the hyphen after the third button clicked, I need to somehow return the current number of characters in the PhoneNum text box, then create an if/else scenario that applies the hyphen after the third button clicked.
    Does anyone know how I can use either JavaScript or jQuery to return the number of characters currently in the PhoneNum text box?

    No problem!
    Basically the thing to remember is that unless you are needing to pass html to the object, you can use text() instead. text() also gives you the raw text without any html formatting (so you can assume what .html() would return)

  • How do you get the integer of a number with more than 10 digits

    I can't seem to be able to get the integer of a number with more than 10 digits.
    ex:
    integer(12345678901.3) returns -539222987 when it should really return 12345678901
    Thanks for the help
    (I'm on director 11 at the moment)

    You can write a Parent script to represent Big Integers. I wrote some code to get you started. It consist of two classes - "BigInt" and "Digit".  At this point you can only add two "BigInts" and print out the value with a toString() function. Note that you pass a String to the "BigInt" constructor.
    In the message window you could enter something like:
    x = script("BigInt").new("999999999999")
    y = script("BigInt").new("100000000000000000004")
    z = x.add(y)
    put z.toString()
    And the output window will show:
    -- "100000001000000000003"
    Here are the two Parent scripts / Classes
    -- Digit
    property  val
    property  next
    on new me, anInt
      val = anInt
      next = 0
      return me
    end new
    -- BigInt
    property  Num
    property  StringRep
    on new me, aString
      Num =  script("Digit").new(Integer(aString.char[aString.length]))
      curNum = Num
      repeat with pos = aString.length - 1 down to 1
        curNum.next = script("Digit").new(Integer(aString.char[pos]))
        curNum = curNum.next
      end repeat
      return me
    end new
    on add me ,  Num2
      curNum = Num
      curNum2 = Num2.Num
      result = curNum.val + curNum2.val
      if result > 9 then
        carry = 1
      else
        carry = 0
      end if
      result = result mod 10
      sum = script("Digit").new(result)
      curSum = sum
      curNum = curNum.next
      curNum2 = curNum2.next
      repeat while curNum.ObjectP AND curNum2.ObjectP
        result = curNum.val + curNum2.val + carry
        if result > 9 then
          carry = 1
        else
          carry = 0
        end if
        result = result mod 10
        curSum.next = script("Digit").new(result)
        curSum = curSum.next
        curNum = curNum.next
        curNum2 = curNum2.next
      end repeat
      repeat while curNum.ObjectP
        result = curNum.val +  carry
        if result > 9 then
          carry = 1
        else
          carry = 0
        end if
        result = result mod 10
        curSum.next = script("Digit").new(result)
        curSum = curSum.next
        curNum = curNum.next
      end repeat
      repeat while curNum2.ObjectP
        result = curNum2.val +  carry
        if result > 9 then
          carry = 1
        else
          carry = 0
        end if
        result = result mod 10
        curSum.next = script("Digit").new(result)
        curSum = curSum.next
        curNum2 = curNum2.next
      end repeat
      StringRep = ""
      me.makeString(sum)
      return me.script.new(StringRep)
    end add
    on toString me
      StringRep = ""
      me.makeString(Num)
      return StringRep
    end toString
    on makeString me, digit
      if not digit then
        return
      end if
      me.makeString(digit.next)
      put String(digit.val) after StringRep
    end makeString

Maybe you are looking for