How to convert nagative integer to positive integer.

int i= (int)System.currentTimeMillis();
System.out.println(i);
The result is nagative
such as;
-585450145
How to convert nagative integer to positive integer.

Isn't it enough to multiply the integer with -1?!?
Or did � understand something wrong?
slaps head
Yes, but an int is only 32 bits wide; a long is 64
bits wide.
The fact that the int is negative isn't "real" - it's
because they cast it to the wrong type. System time
in millis is returned as a long, and that's what it
should be cast to.
%Doh, I'll get me coat.

Similar Messages

  • UDF: How to convert string with sign into integer

    Hi
    I have a number e.g 123456 (xsd:string) and sign - or + (xsd:string) and both are concatenated and fed into UDF. I want this string to be converted into Integer. If I use the below kind of statement it is not working and throwing the below error.
    int BilledAmount  = Integer.parseInt(b[0]);
    Exception:
    RuntimeException in Message-Mapping transformation: Exception:[java.lang.NumberFormatException: For input string: "+000000000006684"]
    Any guess on this issue ??
    Regards
    Kumar

    Hey buddy,
    Hope you are doing gr8, I'm getting ready leaving this friday..:-)
    Aamir b[0] doesn't correspond to the first character of the string. He has multiple input values, hence he is using Context. See my structure and UDF I mentioned above, actually the above is his requirement I believe.
    Yes, If you have + symbol in front of String and if you try to conver to Integer object it will throw an exception. Coz it doesn't make sense to add + symbol at all. if you don't have any sign in front it implies it's positive, am I right? But in case of negative, you need to explicitly include - symbol in front.
    This is the reason that java couldn't able to convert the string that has + symbol in front, but it can in case it has - symbol in front.
    I hope it clears a bit..
    raj.

  • How to convert a character into an integer!!

    I'm a bigginer in Java Programming...
    my problem is that I want to conver the word (red) into a real integer VALUE to be used in a switch case!!
    here's a part of the code which make a problem to me
    String s=c1.getSelectedItem();
                   switch (s)
                        case "red";
                        l1.setBackground(Color.red);
                        break;
                        case "yellow";
                        l1.setBackground(Color.yellow);
                        break;
                        case "green";
                        l1.setBackground(Color.green);
                        break;
    It didn't work, so I need a value like 1 to be assigned to the word (red) and another value like 2 to be assigned to the word (green)...etc
    HOW?.........ANY HELP?

    first of all, there has to be a better way than this, but since you're only using red yellow and green, you could put it inside a char like this
    char r = ((String) c1.getSelectedItem).charAt(0);
    switch (s)
        case 'r':
            l1.setBackground(Color.red);
            break;
        case 'y'
            l1.setBackground(Color.yellow);
            break;
        case 'g':
            l1.setBackground(Color.green);
            break;
    }also I noticed you use ; instead of :
    a case expects a : after case value, and not a ;
    secondary, you could also work with getSelectedIndex Id think, but i'm not sure since I do not know what you're asking a selection from.
    if it's a JList with strings representing colors, you could design a specialisation class of Color with a custom toString (used by the default ListCellRenderer) and then have it return the color object (getselectedItem returns an Object value, so you can cast that into your custom color and assign that to your background, you wouldnt even need a switch case, but I have to agree it's not very simple if you're new to java)
    anyways I hope this helped, i'd first try it with : instead of ; tho, i do not know if switch case support strings since strings are objects and not primitives. so if that doesnt work try to work with the char, if you get duplicates i'd work with getSelectedIndex() which returns an int (you can work with a Color object array with similar running indices where index 0 in the color array is in index 0 of your list array, once again removing the need for a switch case
    well I think i'm done now ;)
    PS: you can use the forums [ code ] and [ code ] tags to make your copy/pasted code much clearer to see. (use them without the spaces, I had to add those or it was not visible)

  • How to convert double to unsigned long integer for cRIO analog output?

    All,
    Having issues sending out my arbitrary waveform to my cRIO analog output. My values are doubles and by the time I send them out, they have been converted to U32 values and are all turning out as zeroes. This led me to assume two things: 1) That cRIO analog output can only output integers since the values need to be deployed in the memory first and 2) that I'm missing a step in the conversion process. My values range from 0-8, therefore I don't expect that the simple conversion tool in labview should make everything into zeroes.
    Any help?

    Since we are using the cRIO's FPGA interface, you really should be doing most of this inside of the FPGA.  Use DMA FIFOs to pass your data between your RT and the FPGA (and visa versa).
    On your FPGA, you can have a loop that just reads the analog inputs at whatever loop rate you want.  You just send the data to the RT using a DMA.
    Similarly, use a DMA to send your analog output values to the FPGA.  The FPGA can have another loop that reads the DMA and writes the value to the analog output.  This should be done in the FPGA since you can have the FPGA send out the values at a given (and deterministic) loop rate.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • How to convert string to an integer in SQL Server 2008

    Hi All,
    How to convert string to an integer in sql server,
    Input : string str="1,2,3,5"
    Output would be : 1,2,3,5
    Thanks in advance.
    Regards,
    Sunil

    No, you cannot convert to INT and get 1,2,3 BUT you can get
    1
    2
    3
    Is it ok?
    CREATE FUNCTION [dbo].[SplitString]
             @str VARCHAR(MAX)
        RETURNS @ret TABLE (token VARCHAR(MAX))
         AS
         BEGIN
        DECLARE @x XML 
        SET @x = '<t>' + REPLACE(@str, ',', '</t><t>') + '</t>'
        INSERT INTO @ret
            SELECT x.i.value('.', 'VARCHAR(MAX)') AS token
            FROM @x.nodes('//t') x(i)
        RETURN
       END
    ----Usage
    SELECT * FROM SplitString ('1,2,3')
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How do I convert a doule to an integer?

    How do I convert a doule to an integer? I know how to do the reverse, but I don't know how to do it backwards. TIA!

    Err, I meant "double," not "doule." It's getting late. -_-                                                                                                                                                                                                       

  • How to convert a number stored as text to as integer with formating

    Hi,
    Can someone say me how to convert a Numeric data that is stored in a Varchar column to an integer.
    Say, I have a Value "-.84566666" in a column which is of data type VARCHAR and I want to show this data as "-0.8456", i.e. I want to display it as an Interger after formating it to have only 4 decimal place value etc.
    Is there any inbuilt function in oracle for this?
    Thanks,

    Take a look at builtin TO_NUMBER / TO_CHAR functions.
    SELECT TO_CHAR(TO_NUMBER('-.84566666'), 'SD9999')
      FROM dual;C.

  • How to convert Date to Integer

    Hi all,
    please send the code How to convert the Date to Integer
    I want like this
    example: Date= 04.11.2002 after conversion the integer is: 4112002
    like this I want if anyone knows this please send it as soon as possible
    byee
    thanks

    Assuming ... String ASimpleDateFormat;
    // do this first
    ASimpleDateFormat = ASimpleDateFormat.replace(".","");
    // then parse
    int DateAsInt = Integer.parseInt(ASimpleDateFormat);

  • How to convert a double to integer ?

    Hi,
    how do convert an output of a pow(2,n) method of Math class to integer. Since this pow(x double, y bouble) gives an output of type double, how do i convert this output to integer if i want the value returned as an integer ?
    thanks
    aron

    By casting (but note that this may not yield the results you want)...
    class Test {
         public static void main(String[] argv) {
              double a = 5.5;
              double b = 6.6;
              int c = (int)(a + b);
              System.out.println(c);
    }

  • How to convert an Integer to byte[] without lose data?

    How to convert an Integer to byte[] without lose data?

    I use the following to convert any java Object to a byte array
    public static byte[] getBytes(Object obj) throws java.io.IOException
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(bos);
            oos.writeObject(obj);
            oos.flush();
            oos.close();
            bos.close();
            byte [] data = bos.toByteArray();
            return data;
    }

  • How to convert an integer to a sting in an expression

    HI,
    I need the convert and integer to a sting in the following example
    In the post expression:
    Step.Result.ReportText = "This is channel No. " + Local.ChNo
    I get an error of unmatched type. (Local.ChNo is integer)
    CAn you show me how to convert the integer to string in this example?
    Thanks
    Rafi

    Hi Rafi,
    Step.Result.ReportText = "This is channel No. " + Str(Local.ChNo)
    or you can format the string Str(Local.ChNo, "%x")
    Check out the help within the function browser.
    Regards
    Ray Farmer
    Regards
    Ray Farmer

  • How to convert from integer to string

    import javax.swing.*;
    import java.awt.*;
    public class Hw extends JFrame{
         JButton[] buttons = new JButton[26];
         public Hw(){
              getContentPane().setLayout(new GridLayout(2,13));
              JButton []buttons=new JButton[26];
              for(int i=65; i<90;i++)
                   buttons=new JButton(i+" ");
                   getContentPane().add(buttons[i]);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              pack();
         public static void main(String[] args) {
              Hw win = new Hw();
              win.setVisible(true);
              win.setLocation(50, 100);
    I have 26 buttons and each buttons will contain a character like A,B,C,D,...
    but i dont know how to convert it from integer to string                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    import javax.swing.*;
    import java.awt.*;
    public class Hw extends JFrame{
         JButton[] buttons = new JButton[26];
         public Hw(){
              getContentPane().setLayout(new GridLayout(2,13));
              JButton []buttons=new JButton[26];
              for(int i=0; i<buttons.length;i++)
                   buttons=new JButton(""+('A'+i));
                   getContentPane().add(buttons[i]);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              pack();
         public static void main(String[] args) {
              Hw win = new Hw();
              win.setVisible(true);
              win.setTitle("Hangman Game");
    tjacobs01  , thnx for urgent reply, but i didnt apply your algorithm inside of the my program, if its possible can u compile the program with your codes..
    its a little complex for me i didnt understand anythind :S                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to convert from java.lang.Integer to int

    Could you please show me
    how to convert from java.lang.Integer to int?
    and how to convert from java.lang.Integer to String?
    Thanks,
    Minh

    Could you please show me
    how to convert from java.lang.Integer to int?
    and how to convert from java.lang.Integer to String?Tip: always keep a browser open on the API docs; if you've got a
    couple of MBs to spare, download the docs; it's very convenient.
    kind regards,
    Jos

  • How to convert an Integer to int

    Integer y = new Integer(1);
    int x = ????(y);
    What is the missing command to do the above conversion ?
    I've tried casting etc.
    It's mid nite and I'm still at work!
    Appreciate all help. Thanks!

    Integer is an Object. int is a primitive base type. to convert an Integer Object into an int:
    //let's say you read a line from a file, and the line is this
    5
    //normally, since files contain characters, you would call a method that reads in String Objects
    //so the 5 is actually a String, which you need to convert to an int to use for math, calculations,
    //expressions, etc.
    String blah = Keyboard.readLine();
    int x = Integer.parseInt(blah);
    // now x equals the int 5.
    hope this helps.

  • How to convert integer to object?

    i want to use a Object array to store two integer variable
    how can i do that?

    Object[] my_array=new Object[2];
    Integer int1=new Integer(7);
    Integer int2=new Integer(42);
    my_array[0]=int1;
    my_array[1]=int2;- Marcus

Maybe you are looking for

  • How to resolve 401 error in HWC SMP2.3

    Hi All,     I did a login Sample with username and password. till now it is working fine but suddenly it is throwing 401 error, Below are my logs. 20140501T145911.752|3|zalyjwtjnccw Mydata:1 -- username: supAdmin|||||3296 20140501T145911.752|3|zalyjw

  • Is there a way to adjust the x-height of a font?

    I'm trying to mix two font together, but they don't have the same x-height. Is there a way I can adjust this? How would I match the x-heights of two existing fonts?

  • Oracle use full physical memory

    hi, I have Oracle 10g on RHEL5, and I examine server with free -m command. [root@prod ~]# free -m total used free shared buffers cached Mem: 3619 3599 19 0 242 2548 -/+ buffers/cache: 809 2809 Swap: 6142 132 6009 from this report i see that free memo

  • Catalyst+awesome35 panel refresh problem

    Hello, met anyone problems with this combination and panel update problem? I tried catalyst stable and beta from arch wiki, and awesome 3.5.1 and 3.5.2 ... And I have problem that, when I switch to any nonempty tag, then my upper panel(tasklist,tagli

  • What do you look for when buying a new printer?

    Ease of use and good drivers. Ever tried to use a Ricoh, Konica Minolta, or Kyocera MFP? Printers are stupidly emotive, get it wrong and it's like you've punched their kids or something.