Comparing two numbers with different formats

Dear Java developers
I am trying to compare two numbers but they have different formats. long x = 8981261369, Object obj = "8,981,261,369".
I am trying to see if this two values are equal which is the case in the example above except one has a thousand separator but not sure how to do that.
How can I lose the thousand separator and just compare them as two long values.
Your input will be much appreciated
Thanks

iu433 wrote:
I need a generic way of doing this. Because sometimes the Object does not have a thousand separator. Can i use some kind of NumberFormat to do this.You'll need to know what formats the string (not the number--as already mentioned, numbers don't have formats) can have, and then try them one by one.
Of course, there can be some ambiguity. Does "123,456" represent one hundred twenty three thousand four hundred fifty six, or is that comma a decimal separator, and it represents one hundred twenty three and four hundred fifty six thousandths?
The point is, you have to have a clear definition of what formats are allowed and how to determine which one it is. There's no magic way for Java to do that for you.

Similar Messages

  • Compare two dates in different format.

    Hi
    I want to compare two dates....one of which is in the timeStamp format ("yyyy-MM-dd HH:mm:ss")
    and the other is in java.util.Date i.e Tue Oct 11 10:22:47 GMT+05:30 2005
    Do I have to tokenise and then compare them.Is there any better approach?
    I want to find out which is greater/smaller one.
    Pls help.
    Regards,
    Sandip.

    I would convert both to Date and compare them. To convert String to Date check java.text.SimpleDateFormat and its parse(...) method.
    HTH
    Mike

  • Compare two dateTime with different timezone

    HI, All,
    I found a strange thing when compare two dateTime in BPEL;
    In my BPEL process, client passed a date time to the process , and the process compare the date time with current data time.
    1.client pass cutoffDate to process
    2. in a switch activity, I compare cutoffDate with current date. code:
    bpws:getVariableData('cutoffDate')<=xpath20:add-dayTimeDuration-to-dateTime()
    but seems this compare ignored the timezone information.
    For example:
    cutoffDate=2010-03-05T06:17:38.838+00:00
    currentDate=2010-03-05T14:10:38.838+08:00 this time =2010-03-05T06:10:38.838+00:00
    but cutoffDate<currentDate == true... seems it ignored the timezone info..
    This is a bug or I used a wrong compare function?
    Thanks.
    Edited by: Colin Song on Mar 5, 2010 3:28 PM

    Hi Colin,
    Please go through below link, there is topic about calculating difference between dates. Hope you find solution.
    http://blogs.oracle.com/reynolds/2007/07/19/
    Please let me know, if still not successful.
    Thx,

  • Trying to compare date columns with differing formats...

    I have an app that created a series of tables via ODBC using ANSI standard datatypes. For most, this isn't a problem, but one in particular is driving me crazy: TIMESTAMP. In Oracle, it shows up as a TIMESTAMP(6). I don't want to mess with the app's tables, so every time there is an insert to their tables, I have a trigger which creates records in corresponding tables I build using standard Oracle datatypes (DATE).
    I have one function that gets called by several of the triggers that retrieves me a specific row to update, and it uses the value from this TIMESTAMP field in the WHERE clause like this (the value is passed into the function as a parmeter):
    SELECT TIMECARD_ID INTO tc_id FROM TS_TIMECARD_MAIN
    WHERE EMP_ID = e_id AND VEHICLE_ID = v_id
    AND IN_TIME <= logout AND OUT_TIME IS NULL; <----
    I seem to have a formatting issue, because unless the "logout" date is a full day later than IN_TIME, it doesn't pull the record (my code does a check to verify there is only one record matching the criteria but I haven't posted it all here for simplicity). I need it to be able to select the correct record with a one second difference.
    I have NLS_TIMESTAMP_FORMAT set to 'YYYY-MM-DD HH24.MI.SS.FF' and NLS_DATE_FORMAT set to 'YYYY-MM-DD HH24:MI:SS'. The relevant describes are included below. Can anyone suggest how to format my query (I expect to use the TO_DATE and TO_CHAR to compensate, but haven't found the right set) so that it resolves properly? Date math is a pain, but it is critical to my purposes.
    Vendor's table
    FIELD3_DATETIME TIMESTAMP(6)
    My table
    TIMECARD_ID NOT NULL NUMBER(10)
    EMP_ID NOT NULL NUMBER(10)
    IN_TIME DATE
    OUT_TIME DATE
    VEHICLE_ID NUMBER(10)
    Also, some sample default output from each table - not sure why formatting is wierd on my table.
    Vendor's table
    UNIQKEY STATUS FORM_ID VEHICLE_NUMBER CREATED_DATETIME
    11515780978071234994451 0 21423 24005 28-JUN-06 05.10.14.000000 PM
    CHECK_DVIR NEW_DVIR SERVICEABLE DETAILS
    1 1 1 everything ok
    INSPECTION_TIME ODOMETER LATITUDE LONGITUDE
    28-JUN-06 05.12.12.000000 PM 119885.1 44.7889490425587 -95.2167677879333
    My table
    TIMECARD_ID EMP_ID IN_TIME OUT_TIME VEHICLE_ID
    5 20044 28-JUN-06 24005

    That sounds a bit complicated. If you post your query I'm sure there will be a simpler approach, perhaps something like
    where  date_timestamp between cast(sysdate -30 as timestamp) and systimestampor if you prefer
    where  date_timestamp between systimestamp - interval '30' day and systimestampas discussed on Re: convert timestamp to date.

  • Compare 2 numbers with different precision

    Hi all,
    Using DB 10.2.0.5, I've encountered a strange behaviour today while trying to compare ORA_ROWSCN with a previous SCN sored in a column.
    SELECT
      h.id HID,
      h.ora_rowscn HSCN,
      o.id OID,
      o.scn OSCN,
      h.ora_rowscn-o.scn DIFF
    FROM
      har@REMOTE h LEFT JOIN other o ON (h.id=o.id)
    WHERE
      h.ORA_ROWSCN > o.scn
    ORDER BY 5 desc ;
           HID       HSCN        OID       OSCN       DIFF
    ...{snip}...
          4213 5093868663       4213 5092916724     951939
    1157 rowsWhile casting o.scn to a number gives me another resultset (this one is correct):
    SELECT
      h.id HID,
      h.ora_rowscn HSCN,
      o.id OID,
      o.scn OSCN,
      h.ora_rowscn-o.scn DIFF
    FROM
      har@REMOTE h LEFT JOIN other o ON (h.id=o.id)
    WHERE
      h.ORA_ROWSCN > to_number(o.scn)
    ORDER BY 5 desc ;
           HID       HSCN        OID       OSCN       DIFF
    ...{snip}...
         70949 5093865558      70949 5093847070      18488
    2114 rowsI got the same result if I use NVL(o.scn,0) rather than TO_NUMBER(o.scn).
    I can't find out why this happens. Obviously, the ">" condition doesn't match when the difference is too small.
    AFAIK, ora_rowscn is a NUMBER while my "scn" column is a NUMBER(12) (which should be sufficient to store my DB or remote DB's SCN).
    Does anyone has an explanation?
    Thanks!

    Thank you, I've marked both of your message Helpful.
    @Solomon, maybe you are right, I'll get a try with Materialized Views.
    About my comparison problem, I think I haven't targeted the right spot. Maybe it is an index+ora_rowscn problem. Here is my execution plan:
    SQL>  SELECT h.id hid, h.ora_rowscn hscn, o.id oid, o.scn oscn, h.ora_rowscn-o.scn diff
    FROM har@REMOTE h, other o
    WHERE
       h.id=o.id(+) AND
       h.ORA_ROWSCN > o.scn
    ORDER BY 5 desc ;
    | Id  | Operation                | Name             | Rows  | Bytes | Cost (%CPU)| Time     | Inst   |IN-OUT|
    |   0 | SELECT STATEMENT         |                  |   683 | 17075 |    94   (4)| 00:00:02 |        |      |
    |   1 |  SORT ORDER BY           |                  |   683 | 17075 |    94   (4)| 00:00:02 |        |      |
    |*  2 |   HASH JOIN              |                  |   683 | 17075 |    93   (3)| 00:00:02 |        |      |
    |   3 |    REMOTE                | HAR              | 13658 |   173K|    46   (0)| 00:00:01 | REMOTE | R->S |
    |   4 |    VIEW                  | index$_join$_002 | 14024 |   164K|    46   (3)| 00:00:01 |        |      |
    |*  5 |     HASH JOIN            |                  |       |       |            |          |        |      |
    |*  6 |      INDEX RANGE SCAN    | IDX_OTHER_SCN    | 14024 |   164K|     3  (34)| 00:00:01 |        |      |
    |   7 |      INDEX FAST FULL SCAN| SYS_C006381      | 14024 |   164K|    54   (0)| 00:00:01 |        |      |
    Predicate Information (identified by operation id):
       2 - access("H"."ID"="O"."ID")
           filter("O"."SCN"<"H"."ORA_ROWSCN")
       5 - access(ROWID=ROWID)
       6 - access("O"."SCN"<"H"."ORA_ROWSCN")
    Remote SQL Information (identified by operation id):
       3 - SELECT "ID","ORA_ROWSCN" FROM "HAR" "H" (accessing 'REMOTE' )Where SYS_C006381 is an index on OTHER.ID and IDX_OTHER_SCN is an index on OTHER.SCN column.
    As soon as I drop the latter index, I get the correct resultset:
    SQL> drop index IDX_OTHER_SCN ;
    | Id  | Operation           | Name     | Rows  | Bytes | Cost (%CPU)| Time     | Inst   |IN-OUT|
    |   0 | SELECT STATEMENT    |          |   683 | 17075 |   117   (3)| 00:00:02 |        |      |
    |   1 |  SORT ORDER BY      |          |   683 | 17075 |   117   (3)| 00:00:02 |        |      |
    |*  2 |   HASH JOIN         |          |   683 | 17075 |   116   (2)| 00:00:02 |        |      |
    |   3 |    REMOTE           | HAR      | 13658 |   173K|    46   (0)| 00:00:01 | REMOTE | R->S |
    |   4 |    TABLE ACCESS FULL| OTHER    | 14024 |   164K|    69   (2)| 00:00:01 |        |      |
    Predicate Information (identified by operation id):
       2 - access("H"."ID"="O"."ID")
           filter("O"."SCN"<"H"."ORA_ROWSCN")
    Remote SQL Information (identified by operation id):
       3 - SELECT "ID","ORA_ROWSCN" FROM "HAR" "H" (accessing 'REMOTE' )Well, I can't figure out what's wrong, but the solution is here. Maybe a limitation of ORA_ROWSCN pseudocolumn...

  • HT204053 I have two iphones with different numbers that I use my apple ID for purchases, etc.  How do I get my second iphone setup on icloud?  I would like to use the features of icloud for both of my iphones.  Thank you

    I have two iphones with different phone numbers that I use.  I have one of them set up on icloud now, but do not know how to set up my second device on icloud.  Both of my iphones use my same Apple ID for purchases, etc.  Is there a simple way to add a device to my icloud account?  Thank you in advance for any help someone may be able to give me.

    To move one of the phones to a different iCloud account (if that's what you want to do), go to Settings>iCloud and turn all synced data to Off.  When prompted, choose to keep the data on your iPhone.  After everything is off, scroll to the bottom and tap Delete Account.  This will delete the account from the phone but not from iCloud so the other phone will not be effected.  Then set up a new iCloud account with a different Apple ID and turn iCloud syncing in Settings>iCloud back to On.  When prompted, choose Merge.  This will upload the data to the new iCloud account.
    You will then have to go to icloud.com and sign into each iCloud account separately and delete any unwanted data that you don't want on the phone syncing with each account.

  • Numbers point to a cell with different formatting to create conditional format

    Hi all, not sure if this has been brought up but my search efforts haven't found anything. I know conditional formatting is not supported in IOS numbers but I saw a buddy do a little trick a while ago and I've been trying to replicate it. On his iPad, he created a numbers spreadsheet that had a logic function (=if). And if that function was true it pointed to another cell with different formatting. The result was, the cell would become the same format as the cell it was pointing too. This created the effect of a conditional format in a sense. I can get this to work with limited effect, only if the cell is a "text" cell and not a formula. As well the background colour doesn't get picked up, only the format of the cell text itself. I'm trying to get in touch with him for help but in the mean time does anyone have any experience in this kind of method?
    Cheers

    As an example:
    If A > B, then A-B, otherwise make it equal this other cell (D1 for example)
    {=if(a1>b1,a1-b1,d1)}
    And in that d1 cell I would make another formula that also does the same subtraction (a1-b1) however knowing it will be a negative number this time, I paint the cell bright red and hopefully the original cell will then look the same since it is now equal to this one.
    Unfortunately it looks like this wont work. The closest thing to doing this trick I have found is pointing to a cell formatted as text, such as a blank cell. Then the original cell takes on the formatting characteristics of the text cell.  The problem is the text cell is useless since it can't do any sort of math. I can't even set the cell to simply equal another one and format it as text only. So far it looks like the only conditional type of trickery I can do is make the numbers disappear by pointing to a blank text cell.
    I hope that helps describe it a little better.

  • How to compare two rows from two table with different data

    how to compare two rows from two table with different data
    e.g.
    Table 1
    ID   DESC
    1     aaa
    2     bbb
    3     ccc
    Table 2
    ID   DESC
    1     aaa
    2     xxx
    3     ccc
    Result
    2

    Create
    table tab1(ID
    int ,DE char(10))
    Create
    table tab2(ID
    int ,DE char(10))
    Insert
    into tab1 Values
    (1,'aaa')
    Insert
    into tab1  Values
    (2,'bbb')
    Insert
    into tab1 Values(3,'ccc')
    Insert
    into tab1 Values(4,'dfe')
    Insert
    into tab2 Values
    (1,'aaa')
    Insert
    into tab2  Values
    (2,'xx')
    Insert
    into tab2 Values(3,'ccc')
    Insert
    into tab2 Values(6,'wdr')
    SELECT 
    tab1.ID,tab2.ID
    As T2 from tab1
    FULL
    join tab2 on tab1.ID
    = tab2.ID  
    WHERE
    BINARY_CHECKSUM(tab1.ID,tab1.DE)
    <> BINARY_CHECKSUM(tab2.ID,tab2.DE)
    OR tab1.ID
    IS NULL
    OR 
    tab2.ID IS
    NULL
    ID column considered as a primary Key
    Apart from different record,Above query populate missing record in both tables.
    Result Set
    ID ID 
    2  2
    4 NULL
    NULL 6
    ganeshk

  • I have 2? How do I sync selected photos from my IPad to my IMac w/o losing all photos on my IPad and getting the phoos o my IMac. ou see I have two IMacs with different sets of photos. Also want to convert all Apple works docs to pages docs on my IMac.

    I have 2? How do I sync selected photos from my IPad to my IMac w/o losing all photos on my IPad which will be replaced with the photos on my IMac.You see I have two IMacs with different sets of photos. Also want to convert all Apple works docs to pages docs on my IMac. Is there and app available to do the former. many thanks. b

    The iPad and related software is designed to sync with only one computer. I suggest transferring the photos from one of your iMacs to the other so that all photos are on one Mac. Same for all other files you want to sync over.
    To get those AppleWorks files to the iPad you'll have to determine if Pages will open them. If it will then use the file sharing feature of iTunes to copy them to Pages on your pad.
    If Pages will not open the AppleWorks files directly you'll have to save them in some format that Pages will read. These include but may not be limited to Pages and Word formats.

  • How can I setup an .indd with two columns with different threads so that I can export to epub?

    Hi all. Sorry, english is not my native language. I´ve made an .indd: each page has two columns with different threads (is a bilingual text). When I export this .indd to .epub only appears one column from a thread following the next thread. What can i do to fix this? My indesign is CS6
    Thank you

    There are fixed format EPUB files as can be used for children's books, etc. where there are a lot of illustrations. However, those are very work-intensive to produce. I've never worked on one.
    Anne-Marie Concepcion did a Lynda.com video on producing one.
    Rorohiko produces a product called ePubCrawler which can help in produced fixed format EPUB files:
    Fixed Layout EPUB Assistant In InDesign: ePubCrawler | Rorohiko ...

  • Can we Compare PDF Output with CSV format

    Team,
    Can we Compare PDF Output with CSV format.
    In Excel I need to two text boxes asking us to browse the files and compare the files PDF & CSV format.
    Please suggest me if we have solution for this.
    Thanks!
    Kiran

    Hi
    I'm afraid the Excel Application does not support this function currently, I am suggesting you to take advantage of a third party component to achieve this goal.
    Thanks for your understanding.
    Best Regards
    Lan
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • I have two users with different music on each itunes and i can only use one library, how do i use both for one iTouch?

    i have two users with different music on each itunes and i can only use one library, how do i use both for one iTouch?

    Chris, I believe this link may have the information you're looking for. Welcome to discussions!
    http://docs.info.apple.com/article.html?artnum=300432

  • Can I use iCloud to sync two devices with different apples Ids?

    Can I use iCloud to sync two devices with different apple ID's

    What do you mean by "apple ID"?  There's an ID you can use at the iTunes store to buy songs, apps, etc.  there's an ID you can use for your iCloud account - the two can be different or the same. So which service are you referring to when you talk about an apple ID?

  • Can I sync two ipods with different ID on the same computer?

    can I sync two ipods with different ID on the same computer?

    Hi,
    Yes you can as long as you have two seperate user accounts on your computer. Hope this helps.
    xxmitchxx90

  • Can I sync two iPads with different users and email addresses on the same computer

    Can I sync two IPads with different users and email addresses on the same computer.

    yes, just make sure you turn off auto-sync to keep everything organized before you try syncing
    on a pc
    edit > preferences > devices - 'prevent ipads, iphones, and ipods from syncing automatically' needs to be checked

Maybe you are looking for