Using Modulus (%) arithmetic operator with decimals

When trying to use the arithmetic operator modulus with decimals there seem to be some errors in the results. Is there a restriction on the number/value of decimals that can be used with this operator? Am I perhaps just using it incorrectly?
example ...
Double valA= new Double("12.4");
Double valB = new Double("1236");
double result = valB.floatValue() % valA.floatValue();
System.out.println("valB : " + valB );
System.out.println("valA: " + valA);
System.out.println("result : " + result);
produces :
valB : 1236.0
valA : 12.4
result : 8.40003776550293
But :
Double valA= new Double("12.5");
Double valB = new Double("1236");
double result = valB.floatValue() % valA.floatValue();
System.out.println("valB : " + valB );
System.out.println("valA: " + valA);
System.out.println("result : " + result);
produces :
valB : 1236.0
valA : 12.5
result : 11.0

Floating point arithmetic in general is not exact. The problem is that you are expecting exact results.
In the second example where you use 12.5 and 1236.0 is just so happens that both of those numbers can be represented exactly, so you do get an exact result.

Similar Messages

  • LabView (8.2) hangs when using I/O operations with traditiona​l NI-DAQ 7.4.4 after aborting LabView program

    Hello!
    We have the following problem:
    LabView (8.2) hangs when using I/O operations with traditional NI-DAQ 7.4.4 after aborting LabView program
    We freshly installed LabView 8.2 (2006) and NI-DAQ 7.4.4 on a PC running Windows XP (Service Pack 3). We built a larger vi that remotely controls a traditional NI-DAQ card (AT-AO-10) on a second PC via NI-VISA 5.0.3. We were successfully running this program until a power failure caused the first computer to crash. After this crash we were unable to start the program again: LabView freezes while loading the vi. LabView itself can be started but freezes when adding I/O operations from the NI-DAQ palette to a block diagram.
    We have tried to re-install NI-DAQ 7.4.4, but it did not help. We then re-installed all NI software, but still no improvement. In the end we decided to reinstall ALL software, first Windows XP, then LabView and finally NI-DAQ 7.4.4. This worked. However, after a few days of running the program we had to abort LabView via Windows Task manager and afterward we again experienced the same problem as before: LabView freezes when loading the program.
    Obviously, we cannot afford to reinstall Windows every time. Are there any known Windows XP / NI-DAQ issues that might cause the freezing of LabView? We would be very grateful for any idea.
    Best regards,
    Matthias

    Hello Sprice,
    Browse the shipping examples according to “Directory Structure” and then select
    DAQ to find the Traditional DAQ examples. 
    There a lot of examples that are written for counters (Counter >>
    daq-stc.llb >> Count Edges (DAQ-STC).vi). 
    What kind of signals are your photons creating?  Are they TTL compatible at a certain
    frequency?  You don’t care about overwriting
    your buffer?
    Respectfully,
    Rob F
    Test Engineer
    Condition Measurements
    National Instruments

  • Arithmetic operations with time

    Hi all,
    I want to do arithmetic operations with time data types. Like
    d1,d2,d3 are of date types
    long diff = d1.getTime()-d2.getTime()-d3.getTime();
    long hours = diff/(60 * 60 * 1000) % 24);
    long mins = diff / (60 * 1000) % 60;
    long secs =  diff / 1000 % 60;
    When i am entering time for d1 as 4:00:00, d2 as 9:00:00 and d3 as 1:00:00, i am getting hours & mins in negative values.
    Can anyone suggest how to do this operation

    hi sahithi,
    when d1 d2 and d3 are date types how can u enter or set 4:00:00 to it, which is time representation.
    what exactly u are trying to do ...
    and it is obvvious that d1-d2-d3 is 4:00:00 -9:00:00 -1:00:00 here u can see that 9 is greater and its sign is predominant according to this expression. hence diff is negative value. and then as usuall hours and secs are also in negative.
    any how follow below code you can solve yoru issue i hope
    String fromdate = "11/03/14 09:29:58";
        String enddate = "11/03/14 09:33:43";
        Custom date format
        SimpleDateFormat format = new SimpleDateFormat("yy/MM/dd HH:mm:ss");
        Date d1 = null;
        Date d2 = null;
        try {
            d1 = format.parse(dateStart);
            d2 = format.parse(dateStop);
        } catch (ParseException e) {
            e.printStackTrace();
        long diff = d2.getTime() - d1.getTime();
        long diffSeconds = diff / 1000 % 60;  // for seconds
        long diffMinutes = diff / (60 * 1000) % 60; // for minute
        long diffHours = diff / (60 * 60 * 1000); // for hours
    wdComponentAPI.getMessageManager().reportSuccess
    ("Seconds---> " + diffSeconds +"sec");
    wdComponentAPI.getMessageManager().reportSuccess
    ("Minutes---> " + diffMinutes + " min.");
    wdComponentAPI.getMessageManager().reportSuccess
    ("Hours--->" + diffHours + " hrs.");
    Regards
    Govardan

  • How to use sql "IN" operator with named bind variable in where clause ?

    Can one bind variable be used for the "IN" list ('1','2','3') ?

    rob,
    No worries. Glad it helped. Glad to see also that you're doing things right and trying to use bind variables ;)
    May I suggest adding "SOLVED" to the title of the original post?
    Best,
    John

  • Using the LIKE operator with wildcards to match names

    I am using SQL in ColdFusion 9 to match names in an MS Access 2003 database table.
    The Visitors field of MyTable contains the name "Smith" in six records.
    1. Smith Jones Wilson
    2. Smith, Jones, Wilson
    3. Smith(Jr.), Jones, Wilson
    4. Jones Wilson Smith
    5. Wilson Smith Jones
    6. Smith
    7. Smithson, Jones, Wilson
    8. Jones, Wilson, Arrowsmith
    To find out which records contain the name Smith (but not Smithson or Arrowsmith) I now need to write four "OR" lines:
    WHERE MyField LIKE 'Smith[!a-zA-Z]%'  (finds only the Smiths in records 1, 2 and 3)
             OR MyField LIKE '%[!a-zA-Z]Smith'  (finds only the Smith in record 4)
           OR MyField LIKE '%[!a-zA-Z]Smith[!a-zA-Z]%' (finds only the Smith in record 5)
           OR MyField = 'Smith'   (finds only the Smith in record 6)
    I would like to know how to combine these four lines into one which would find all six records containing Smith.
    Thank you for your help.

    As this is a SQL-specific question, you might be better off asking it on a SQL forum?  Does Access even support regexes?
    For a CF the regex you'd be after "\bsmith\b".  You should read the Access regex reference to see if it supports this.  A CF regular expression is no use to you here as the comparison needs to be done on the DB,  not in CF.
    Adam
    Misread the question.  Revising.

  • Arithmetic operations with date characteristics.

    Hi gurus....i want to to subtract 2 time characteristics directly in BEx so i can get de difference between 2 dates. how can i do it?
    In fact the specific requirement is to subtract from de execution query date a time characteristic.
    Is there a sysdate variable that gives me the execution date of the query??? or i have to use a user exit variable to do this?
    Thanks and regards.

    hi Rafael,
    take a look
    http://www.sd-solutions.com/documents/SDS_BW_Replacement%20Path%20Variables.html
    hope this helps.

  • Arithmetic operations using Picklist field values

    Hi,
    I tried to multiply a picklist field value as below and wanted to store the result in a field (datatype = Integer or Number) using a workflow which triggers based on the Trigger Event "Before modified record saved".
    Criticality = [<plFrequency_of_Occurrence_ITAG>] * 10
    It throws an error:
    "Update Criticality : Value too long for field 'ZNum_0' (maximum size 16). (SBL-DAT-00235)(SBL-ODS-00500)"
    Can't we do arithmetic operations on the Picklist fields? I believe this is because the values are being stored as text??
    Do we have a function to convert the character field to numeric before we perform any arithmetic operations?
    Thanks,
    Sriram

    Hi,
    You're right, you can't perform arithmetic operations with a number and a text. That's why you get the error.
    Today, there's no function you can use to convert a text to a number.
    You'll need to create a SR asking for a Change Request.
    Regards,
    Max

  • Formating and operating with integer values

    I am new to XML Publisher.
    I have a task to make a layout using rtf. The problem is that I must do an arithmetical operation using data generated from a system report. I must not modify the report!!!
    The value retrieved from report is of X.Y format which means a time period (X - years, Y - months). So I want to split this value in two - one for years and other for months with a posibility of making arithmetical operations over them. Is it possible?? And if so, cand anybody give me a solution for this...?

    ok, back to the problem. As I red in the XML Publihser Users Guide there is a posibility to transform strings in numbers, but I can't figure out how it works! As speaking of my problem I can not do arithmetical operations with that value (YEARS.MONTHS). I tried the to_number function described in XML Publisher User's Guide (page 7-3) over the vlaue x.y, I tried to change the point (x.y) to a comma (x,y) and again aply to_number function over resulted value, but it doesn't work. What do I do wrong?
    I tried the solution of spliting the x from y, but I run into a problem again. The years part x has a variable length so I can't get the y part. (the substr function didn't worked with negative start position - substr(DATE, -3, 3))
    Generaly I'm a very confused about XML Publisher. There are examples in User's Guide which didn't work for me...
    If anybody has some links with documentation about XML Publisher, other than those from ORACLE, please share them with me.
    10x!

  • VEctor: Problem in arithmetical operation

    The problem with the following code is that when an element is accessed with v.elementAt() the compilation is OK. But if I try to do some arithmetic operation on the element, it won't compile, giving the message -
    VectorDemo.java:36: operator * cannot be applied to java.lang.Object, int
    System.out.println("Result: "+v.elementAt(3)*2);
    Is it because of <Object> type declaration of Vector? If so how to do arithmetic operation with an element of a vector which may have Double, Float or Integer type of elements in the same vector?
    import java.util.*;
    class VectorDemo
         public static void main(String args[])
              Vector<Object> v=new Vector<Object>(3,2);
              System.out.println("Initial size: "+v.size());
              System.out.println("Initial capacity: "+v.capacity());
              v.addElement(new Integer(1));
              v.addElement(new Integer(2));
              v.addElement(new Integer(3));
              v.addElement(new Integer(4));
              System.out.println("Capacity after four additions: "+v.capacity());
              v.addElement(new Double(5.45));
              System.out.println("Current capacity : "+v.capacity());
              v.addElement(new Double(6.08));
              v.addElement(new Integer(7));
              System.out.println("Current capacity : "+v.capacity());
              v.addElement(new Float(9.4));
              v.addElement(new Integer(10));
              System.out.println("Current capacity : "+v.capacity());
              v.addElement(new Integer(11));
              v.addElement(new Integer(12));
              System.out.println("First element : "+v.firstElement());
              System.out.println("Last element : "+v.lastElement());
              System.out.println("Find Result: "+v.elementAt(3));     //<------ if replaced with:
                                    //System.out.println("Find Result: "+v.elementAt(3)*2);
              if(v.contains(new Integer(3)))
                   System.out.println("Vector contains 3.");
              Enumeration vEnum=v.elements();
              System.out.println("\nElements in vector: ");
              while(vEnum.hasMoreElements())
                   System.out.println(vEnum.nextElement()+" ");
              System.out.println();
    }

    Here's the correct code.
    import java.util.*;
    import java.lang.Number;
    class VectorDemo
         public static void main(String args[])
              //initial size is 3, increment is 2
              String s;
              int i=0;
              Vector<Number> v=new Vector<Number>(3,2);
              System.out.println("Initial size: "+v.size());
              System.out.println("Initial capacity: "+v.capacity());
              v.addElement(new Integer(1));
              v.addElement(new Integer(2));
              v.addElement(new Integer(3));
              v.addElement(new Integer(4));
              System.out.println("Capacity after four additions: "+v.capacity());
              v.addElement(new Double(5.45));
              System.out.println("Current capacity : "+v.capacity());
              v.addElement(new Double(6.08));
              v.addElement(new Integer(7));
              System.out.println("Current capacity : "+v.capacity());
              v.addElement(new Float(9.4));
              v.addElement(new Integer(10));
              System.out.println("Current capacity : "+v.capacity());
              v.addElement(new Integer(11));
              v.addElement(new Integer(12));
              System.out.println("First element : "+v.firstElement());
              System.out.println("Last element : "+v.lastElement());
              System.out.println("Result: "+Integer.parseInt(v.elementAt(3).toString())*2);
              if(v.contains(new Integer(3)))
                   System.out.println("Vector contains 3.");
              //enumerate the elements in the vector.
              Enumeration vEnum=v.elements();
              System.out.println("\nElements in vector: ");
              while(vEnum.hasMoreElements())
                   System.out.println(vEnum.nextElement()+" ");
              System.out.println();
    }

  • LIKE Operator with Clobs

    Hi, Having Problems using the LIKE Operator with the Clob Datatype. Does any one know if its possible.
    Thanks
    Emer

    It's not possible.
    try use DBMS_LOB.INSTR instead...

  • Arithmetic operator

    Can't you use all Arithmetic operators with characters?

    What would the value be of doing this, evenassuming
    you can?it's easy:
    2 * '.' == ':'
    't' - '-' == l
    '~' + 'o' == � (that's &otilde; in
    html)
    'p' ^ -1 == 'd'
    sqrt('A') == 'a'
    and so on...And if code were written like that, it would be time to get a rope to have a hangin' for the coder...

  • MINUS operation with remote table

    Hi all,
    Please help me with this problem.
    I have two tables with 20 columns each, one table resides on one database and the other table is accesed through a db link. Both tables contains +800,000 records.
    I need to know the record differences between these two tables - this is a periodical process, not for once- , I am using a MINUS operation with full scan, the problem is that my query is taking long time to finish : +20 min. Also i tried witn COLUMN IN() instead MINUS but my query performance is worst.
    Do you know another way to get the record differences with a better performance?
    Thanks in advance
    Edited by: Osymad on Jun 18, 2012 5:12 PM

    Osymad wrote:
    Hi all,
    Please help me with this problem.
    I have two tables with 20 columns each, one table resides on one database and the other table is accesed through a db link. Both tables contains +800,000 records.
    I need to know the record differences between these two tables - this is a periodical process, not for once- , I am using a MINUS operation with full scan, the problem is that my query is taking long time to finish : +20 min. Also i tried witn COLUMN IN() instead MINUS but my query performance is worst.
    Do you know another way to get the record differences with a better performance?
    Thanks in advance
    Edited by: Osymad on Jun 18, 2012 5:12 PMhttp://www.oracle.com/technetwork/issue-archive/2005/05-jan/o15asktom-084959.html
    Search for "Comparing the Contents of Two Tables"
    Cheers,

  • Error while using between operator with sql stmts in obiee 11g analytics

    Hi All,
    when I try to use between operator with two select queries in OBIEE 11g analytics, I'm getting the below error:
    Error Codes: YQCO4T56:OPR4ONWY:U9IM8TAC:OI2DL65P
    Location: saw.views.evc.activate, saw.httpserver.processrequest, saw.rpc.server.responder, saw.rpc.server, saw.rpc.server.handleConnection, saw.rpc.server.dispatch, saw.threadpool.socketrpcserver, saw.threads
    Odbc driver returned an error (SQLExecDirectW).
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned from OBIS. [nQSError: 27002] Near <select>: Syntax error [nQSError: 26012] . (HY000)
    can anyone help me out in resolving this issue.

    Hi All,
    Thank u all for ur replies, but I dint the exact solution for what I'm searching for.
    If I use the condition as
    "WHERE "Workforce Budget"."Used Budget Amount" BETWEEN MAX("Workforce Budget"."Total Eligible Salaries") AND MAX("Workforce Budget"."Published Worksheet Budget Amount"",
    all the data will be grouped with the two columns which I'm considering in the condition.
    my actual requirement with this query is to get the required date from a table to generate the report either as daily or weekly or monthly report. If I use repository variables, variables are not getting refreshed until I regenerate the server(which I should not do in my project). Hence I have created a table to hold weekly start and end dates and monthly start and end dates to pass the value to the actual report using between operator.
    please could anyone help me on this, my release date is fast approaching.

  • So I just bought a used MacBook from Amazon with OSX 10.5.8.  I am trying to install new software and operating system, but I don't have the passwords to the Users set up in the computer.  What do I do?

    So I just bought a used MacBook from Amazon with OSX 10.5.8.  I am trying to install new software and operating system, but I don't have the passwords to the Users set up in the computer.  What do I do?

    Put your install DVD into the optical drive (CD/DVD drive) and reboot. Be sure to either use the disc that came with your Mac, or, if you installed a later Mac OS X version from disc, use the newer disc. As soon as you hear the boot chime, hold down the "c" key on your keyboard (or the Option Key until the Install Disk shows up) until the apple shows up. That will force your MacBook to boot from the install DVD in the optical drive.
    When it does start up, you'll see a panel asking you to choose your language. Choose your language and press the Return key on your keyboard once. It will then present you with an Installation window. Completely ignore this window and click on Utilities in the top menu and scroll down to Reset Password. After resetting the password use Startup Disk from the same menu to choose your hard drive for startup and restart.

  • Hello guys..does anybody know how to install and use adobe master collection with the new lion?   I need to use Flash and illustratore, but apparently those programmes are incompatible with the new operative sistem...   I am a new mac users and I'd like t

    Hello guys..does anybody know how to install and use adobe master collection with the new lion?
    I need to use Flash and illustratore, but apparently those programmes are incompatible with the new operative sistem...
    I am a new mac users and I'd like to know if there are other similar programmes I can use with lion!

    Lab79 wrote:
    Are you on Apple's payroll?
    well dude I can only let you know that as I work with those programme I don't have to pay for it is my company that pays the programme I whant to use( that's why I was asking if there where other programmes ..that I could use with lion insted that Illustrator and Flash!)..I know Adobe since 2005 and I can say that Adobs products are very good...I think that if it's an Adobe probleme or fault ..they will solve it very soon...but unfortunally I have the impression that after Jobs passed away Appel decided to change politics..and everything started to go very bad! (see FCP X)..
    good luck with apple dude..
    Where is the Apple problem? I have CS4 and CS5 running perfectly fine on my Macbook Pro. Installed 5 after Lion upgrade. Worth every cent. Adobe did have some catching up to do with Lion but with the CS5.5 update all runs fine. But not yours. So it is a problem with the Lion OS? You say you have been with Adobe since 2005. So you would be aware of all the other issues that Adobe had catching up with past Oss in Mac and Windows then. They get it right, but it is up to them. It is not up to Apple, nor Microsoft for that matter, to run around and check that every software developer in the world is running their business properly.
    And what has politics got to do with anything. Some people just have to blame Software for their poor Hardware maintainence of failure of the same.
    <The only think I can really do is to go back on my old windows...give back this orrible lap top and ask for my money back!>
    Great suggestion. You should go with that one, but good luck getting a refund.
    Bye

Maybe you are looking for