Float Calculation

Dear all,
I am having a calculation problem now.
Float.parseFloat(reuquest.getParameter("Amt");
When I input the value of 'Amt' as 178229.26. After it is passed into Float.parseFloat(), it always becomes 178229.25. Besides, I have tried another approach as follows, I still got the same result.
new BigDecimal(request.getParameter("Amt")).floatValue()
I just think if the value is passed into any float property, its value will be changed.
If anyone know the solution, please tell me! Thank you very much.
Betty

just to be sure: you should be aware that even wehn double is much more accurate than float, there is an amount of inherent inaccuracy that can hit you when you are not anticipating it. if you need trusty calculations ("Amt" sounds like that, if it's german), you maybe should use BigDecmial (it's very inperformant on the other hand).
~klemens
p.s.: no, i don't want any duke. being a voice in the eternal battle against evil floats in office calculations is reward enough. ((-;

Similar Messages

  • Is there a floating calculator for the mac

    I would like my desktop calculator to follow me when I change windows. I call this a floating calculator but perhaps there is a different name for this. Is one available for download into Mountain Lion
    Thank Bruce

    The Apple Support Communities are an international user to user technical support forum. As a man from Mexico, Spanish is my native tongue. I do not speak English very well, however, I do write in English with the aid of the Mac OS X spelling and grammar checks. I also live in a culture perhaps very very different from your own. When offering advice in the ASC, my comments are not meant to be anything more than helpful and certainly not to be taken as insults.
    You can have the Calculator app appear in all Desktops. Open the app, right click the app's icon in the Dock and choose Options/All Desktops. However, Fullscreen apps are not treated as desktops and the app will not follow you to an open FS app.

  • Float calculation in VS2010 and VS2012/VS2013 C++

    Hi,
    There are some difference in float calculation in VS2010 and VS2013/VS2012.   (vc++)
    VS2010 by default uses FPU instruction for float calculation. while VS2013 by default , uses SSE2 instruction for the same.
    Can you suggest which is the most accurate result. FPU or SSE2
    Regards,
    Alphonse

    That tends to depend on the code you write. Without being a floating point expert I'll say that I find SSE2 preferable because it provides consistent results. Consistency isn't the same thing as accuracy but it's usually more valuable.
    Consider the following example adapted from "What Every Computer Scientist Should Know About Floating-Point Arithmetic" (required reading if you really care about
    floating point accuracy):
    void test(float a, float b) {
    float q = a / b;
    if (q == a / b)
    printf("Equal\n");
    else
    printf("Not Equal\n");
    int main() {
    test(3, 7);
    This code prints "Not Equal" when FPU is used and "Equal" when SSE2 is used. Needless to say, the SSE2 result is much more desirable.
    The reason for this is that FPU tends to perform calculations at a higher precision than requested. The VC++ runtime configures the FPU to use double precision and as a result all float calculations are actually done at double precision and the result
    is converted to float when required by the code (like when storing into a float variable). In the above example the right side of == will be a double precision value while the left side is a double precision value that was previously rounded to single precision.
    If you use only doubles it's less likely to run into such issues but as far as I can tell it's not completely impossible. The FPU rounds only the mantissa part to double precision but leaves the exponent alone. Presumable this can cause issues if very
    large values are involved.
    SSE2 doesn't suffer from this problem, it has distinct instructions for single and double precision and VS2013 makes use of them. If you use floats the calculation is done using single precision, if you use doubles the calculation is done using double precision; nothing
    less, nothing more.

  • Same float code compiled differently on different machines

    Hi,
    Scenario:   same project build on different machines. and then both the  application executed on
    same machine .. giving  slightly different results..(like 23.07499   to 23.07500)
    project involves many float operations.  project build on vs2013. c++
    there is difference oberved in the final value of float calculations..  like 23.07499   to 23.07500
    seems , Same float code compiled differently on different machines,  any input
    Regards,
    james

    >Scenario:   same project build on different machines. and then both the  application executed on same machine ..
    giving  slightly different results..(like 23.07499   to 23.07500)
    Do you get consistent results with the same executable each time you
    run it?
    Assuming you do, and the only difference is the EXEs, what's the
    difference between them - there must be something. Have a look at "How
    to compare binary images of the same project builds"
    https://support.microsoft.com/en-us/kb/164151/ and see if that sheds
    any light onto the issue.
    Dave

  • Why use floats in graphics methods?

    Since coordinates are specified in pixels, why do
    methods like Line2D.Float() take floating point numbers
    instead of integers? Dont floats take more time
    and memory?

    As far as I know, float calculations indeed require more processing power as apposed to integer ones. I'm not quite sure why floats and doubles are used in a number of graphics related methods either, because it's not quite likely you'll ever have a screen dimension of 1024.78 by 768.54 for instance (yet, class java.awt.Dimension returns width and height of screensize as doubles!).
    I think a float, like int, consumes 32 bits -thus 4 bytes- of memory space. So as far as memory goes, there's no difference.
    Could someone else enlighten us regarding the use of float and double precision variables where it -at first glance- doesn't seem to make sense?

  • Modbus register readings, double type Shared Variable 32000

    Hello
    I am new to labview and modbus and have been trying to communicate with a control card using the VIs in the standard modbus library in labview 8. This might be a very simple question, it relates to the output of the "read holding register" or "function code 0x03" . All the results I have been getting are in 5 digit decimal form, I have read in another post that this may be the "double type Shared Variable" and that it can be converted or typecasted to "ieee 754 type" i.e. as actual measurement values. I was wondering if it is possible for 5 digit "double type shared variable" that are greater than the 32000, i.e such as 50119 or 50294, to be converted to "ieee 754 type". Or even if there are standard methods that can perform this type of conversion in general.
    Thanks in advance

    Maybe this will help.
    http://forums.mrplc.com/index.php?showtopic=30
    http://www.simplymodbus.ca/FAQ.htm#Types
    What are data types?
    The example for FC03 shows that register 40108 contains AE41
    which converts to the 16 bits 1010 1110 0100 0001
    Great! But what does it mean? Well, it could mean a few things.
    Register 40108 could be defined as any of these 16-bit data types:
         A 16-bit unsigned integer (a whole number between 0 and 65535)
                        register 40108 contains AE41 = 44,609 (hex to decimal conversion)
         A 16-bit signed integer (a whole number between -32768 and 32767)
                                                            AE41 = -20,927
                  (hex to decimal conversion that wraps, if its over 32767 then subtract 65536)
         A two character ASCII string (2 typed letters)
                                                            AE41 = ® A
         A discrete on/off value (this works the same as 16-bit integers with a value of 0 or 1.
                                                  The hex data would be 0000 or 0001)
    Register 40108 could also be combined with 40109 to form any of these 32-bit data types:
         A 32-bit unsigned integer (a number between 0 and 4,294,967,295)
                                 40108,40109 = AE41 5652 =  2,923,517,522
         A 32-bit signed integer (a number between -2,147,483,648 and 2,147,483,647)
                                                           AE41 5652 = -1,371,449,774
          A 32-bit double precision IEEE floating point number.
          This is a mathematical formula that allows any real number (a number with decimal
           points) to represented by 32 bits with an accuracy of about seven digits.
                                                           AE41 5652 = -4.395978 E-11
          Here is a spreadsheet IEEE float calculator for inputs of 4 bytes or 2 words.
          To download a copy, right click and select Save Target As...
         A four character ASCII string (4 typed letters)
                                                             AE41 5652 = ® A V R
    More registers can be combined to form longer ASCII strings.  Each register being used to store two ASCII characters (two bytes).

  • Need Java Help on a Mortgage program

    I keep getting the following error.
    java:20: illegal start of expression
    public Scanner myScanner = new Scanner(System.in);
    /*Danielle Safonte*/
    /* Week 2 Mortgage Calculator*/
    import java.util.Scanner;
    import java.io.*;
    import java.text.*;
    public class Week2Assignment
    int principle = 200000;
    float interest = .0575;
    int term = 30;
    int months;
    float paymentdue;
    float calculation;
    public static void months()
    public Scanner myScanner = new Scanner(System.in);
    System.out.print("What month of the loan is this?" + months);
    if (months = term) {
    System.out.print("You have paid off your loan");
    else
         months = myScanner.next();
         float Jinterest = (interest / (months*100));
         calculation = principle * (Jinterest/(1-(1+Jinterest)^(-months))); /*Monthly payment*/
         float Minterest = principle * Jinterest; /*This months interest*/
         float Mprinciple = calculation - Minterest; /*This months principle*/
         float newBalance = principle - Mprinciple; /*This calculates the new principle*/
         if (newBalance = princple) {
              System.out.print("You have paid off your loan");
         else
              System.out.print("This months payment is: $", calculation); /*Displays the current months payment*/
              System.out.print("You have $", newBalance," left on your loan"); /*Displays the new principle balance*/
              System.out.print("This months principle is: $", Mprinciple ); /*Displays the new principle balance*/
    }

    It is in my post at 10:02, but here it is again:
    These are the errors that I am left with. I worked through the rest.
    .java:29: '.class' expected
    months = myScanner.next(int);
    ^
    .java:29: ')' expected
    months = myScanner.next(int);
    ^
    2 errors
    Tool completed with exit code 1
    import java.util.Scanner;
    import java.io.*;
    import java.text.*;
    public class Week2Assignment
    int principle = 200000;
    double  interest = .0575;
    int term = 30;
    int months;
    float paymentdue;
    float calculation;
    public void months()
    Scanner myScanner = new Scanner(System.in);
       System.out.print("What month of the loan is this?" + months);
    if (months == term) {
       System.out.print("You have paid off your loan");
    else
         months = myScanner.next(int);
         double Jinterest = (interest / (months*100));
         calculation = principle * (Jinterest/(1-(1+Jinterest)^(-months))); /*Monthly payment*/
         float Minterest = principle * Jinterest; /*This months interest*/
         float Mprinciple = calculation - Minterest; /*This months principle*/
         float newBalance = principle - Mprinciple; /*This calculates the new principle*/
         if (newBalance == princple) {
                 System.out.print("You have paid off your loan");
         else
                 System.out.print("This months payment is: $", calculation); /*Displays the current months payment*/
                 System.out.print("You have $", newBalance," left on your loan"); /*Displays the new principle balance*/
                 System.out.print("This months principle is: $", Mprinciple ); /*Displays the new principle balance*/
    }

  • Math in J2ME

    Hi!
    I need to do float calculations in J2ME.
    anybody knows any existing customized classes to replace java.lang.Float and java.lang.Math ?
    but such that wont cause loose of precision in the float calculations.
    thanks

    You can you JMFP.
    A Unlimited Java Math Fixed Point library.
    You can find it at http://sourceforge.net/projects/jmfp/

  • JFormattedTextField getValue() is returning the wrong type

    So this is a very strange I've found in my ever-growing project I've been working on. I have four text boxes set up. Essentially, one is the total, the second is part_one, the third part_two, and the last the_rest.
    They've all been declared and initialized identically, e.g.:
    JFormattedTextField total = new javax.swing.JFormattedTextField(java.text.NumberFormat.getCurrencyInstance(Locale.US));
    JFormattedTextField part_one = new javax.swing.JFormattedTextField(java.text.NumberFormat.getCurrencyInstance(Locale.US));
    JFormattedTextField part_two = new javax.swing.JFormattedTextField(java.text.NumberFormat.getCurrencyInstance(Locale.US));
    JFormattedTextField the_rest = new javax.swing.JFormattedTextField(java.text.NumberFormat.getCurrencyInstance(Locale.US));the_rest is supposed to auto update as any of the other three are changed (the_rest = total - part_one - part_two)
    However, I'm having issues updating the text boxes, as I am getting a ClassCastException when trying to calculate the_rest:
    float calculated = calculateTheRest((Float)total.getValue(), (Float)part_one.getValue(), (Float)part_two.getValue());
    the_rest.setValue(calculated);And my calculateTheRest() function:
    private float calculateTheRest(Float total, Float part_one, Float part_two) {
            if(total == null)
                total = 0.0f;
            if(part_one== null)
                part_one = 0.0f;
            if(part_two== null)
                part_two = 0.0f;
            return total - (first + second);
    }What am I doing wrong here?
    Edited by: GranoblasticMan on Sep 16, 2008 7:49 AM
    Fixed typos... was hand-retyping this, not copy-and-pasting.
    Edited by: GranoblasticMan on Sep 16, 2008 7:51 AM
    And the exact error message I'm getting is:
    Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.Long

    For the time being, I've changed my calculateTheRest() function:
            private float calculateTheRest(Object total, Object part_one, Object part_two) {
            if(total == null)
                total = new Float(0.0f);
            if(part_one == null)
                first = new Float(0.0f);
            if(part_two == null)
                second = new Float(0.0f);
            return convertToFloat(total) - (convertToFloat(part_one) + convertToFloat(part_two));
    private float convertToFloat(Object o) {
            if(o instanceof Number)
                return ((Number)o).floatValue();
            return Float.NaN;   
    }But I'm still wondering why this would happen. Do FormattedTextFields not actually store decimal values?

  • Math libs for J2ME

    Hi!
    I need to do float calculations in J2ME.
    anybody knows any existing customized classes to replace java.lang.Float and java.lang.Math ?
    but such that wont cause loose of precision in the float calculations.
    thanks

    See my experience : http://forum.java.sun.com/thread.jsp?forum=50&thread=138662
    It's so simple to reintroduce float and double, mathlib etc. only thing required : having the
    correspondant libraries with C compiler on your specific hardware.
    Regards.

  • Error in mapping for floating Number calculation

    Hi All,
       I have a small doubt in floating number calculation in Mapping.
    Actually i am geting a floating point number and calculating the SUM and generating the output. The input is of 2 decimal places(Ex: 26.02  and 26.03 ), but when it is adding all the values it is generating a three digit decimal number (Ex: 52.050003)
    I dont know from where it is geting one extra number "2" in the output.
    Please find the code for the same and let me know if i need to do something else to get ride of this.
       //write your code here
    float sum=0;
    if(a != null && a.length > 0.00)
       for ( int j =0; j<a.length;j++)
        sum  =  sum + Float.parseFloat(a[j]);
       result.addValue(String.valueOf(sum));
    else
    result.addValue("0");
    Thanks in Advance,
    JAY

    Jay,
    Please use the below code and let us know, if it helps.
    BigDecimal sum= new BigDecimal("0");
    BigDecimal bd;
    if(a != null && a.length > 0.00)
    for ( int j =0; j<a.length;j++)
    bd=new BigDecimal(a[j]);
    sum=sum.add(bd);
    result.addValue(""+sum+"");
    else
    result.addValue("0");
    in import section - java.math.*;
    raj.
    Edited by: Raj on Feb 18, 2008 11:11 AM

  • 128-bit floating point calculations

    I'm looking to buy a used SPARC. Which model is the oldest that provides
    C or fortran 128-bit floating point calculations? Does every 64-bit CPU
    have 128-bit quad real numbers?
    Ron

    The AMD 64-bit processor does not support 128-bit
    floating numbers. I need a Sparc processor that
    does.And yet your question has just what to do with Java -- why did you create a userid and post this question in the Java forums?
    A response "Does every person have ten fingers?"
    shows me that you don't know much about writting
    computer programs that have more than 16 significant
    decimal digits.I wouldn't infer that - but now that you've proven to be a whiny little snot, I'm sure everyone is just going to want to help you here.

  • Calculating with float...

    Hi, how can I manage the following calculation, without external librarys.
    A = X / (Z / Y)
    A, X, Z, Y are all short, but the 2 results shouldn be rounded...is it possible in java me to calculate something like this ?
    ...mhh...Im sorry for this newbish question, maybe its quite simple, but Im wonder about..

    No, you cannot do this without external libs in CLDC 1.0. floating point is not supported.
    You might scale all numbers factor 10 or 100 and then do the division. It will give you more accuracy.

  • How fast does Labview perform integer, float and matrix calculations?

    What is the speed of a modern CPU? Ok it is 3Ghz, one to four cores etc. but how much work can I get done in one clock cycle at this speed?
    This kind of questions have been in the back of my head for some time, so I decided to test it. Of course using Labview since it so easy to to use!
    I wrote a really simple program that performed 10000 adds 3 to an 32 bit integer in a loop. It then repeats this until 1000ms has elapsed and calculates the MegaInts (or whatever I should call it). I then did the same thing by adding 3 to a matrix of 10000 32bit ints.
    On and dual core 3Ghz PC from 2005 I got 261 Mints in a loop, and 1400 Mints in matrix. Only one core seems to be used, CPU load aorund 50%. So every two clock cycles or so I get some work done in a matrix calculation. Also older 1,8Ghz Celeron computers performs about the same in this test, even though they feel very slow in normal use.
    On a newer 4/8 core 2,8Ghz PC from this year I got 830 Mints in a loop, and 5900 Mints in matrix. Only one core seems to be used, CPU load aorund 12%. So actually more than one add per clock cycle!
    This indicates that either the compiler is smarter than me and does not to all integer adds, or the CPU is smart and do them very fast!
    See this as not the complete benchmark of Labview in integer, float and matrix calculations, but as a teaser to make you do your own tests.
    Play around and have fun!

    Norbert_B wrote:
    Yamaeda wrote:
    A standard loop only runs in 1 thread,[...]
    That is not true.
    A standard loop follows the clumping algorithm during compilation. Clumps can be distributed on any number of threads.
    So, a standard loop CAN be distributed between several threads.
    There are, however, some settings and structures which will result in a single thread per loop:
    - Setting the calling VI to "subroutine" priority (not recommended)
    - Using a Timed Loop instead of a standard one
    - AFAIK: Containing the loop in an InPlace Element Structure with "Data Value Reference" border nodes
    There is at least one additional option, but it is so unlikely (as it messes up with most of LV!) that i will not point it out here.....
    Norbert
    Why would we have parallellization options for a loop if it's already multithreaded? I'd love if loops would automatically parallellize.
    If you mean the content inside the loop, then it'll follow ordinary optimization and use several threads if possible. In this case OP mentioned 1 cpu was at 100%.
    /Y
    LabVIEW 8.2 - 2014
    "Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
    G# - Free award winning reference based OOP for LV

  • Floater accrual interest and tax calculation

    I have one secutity ID 353022, in security position cash flow as attached, I want to know how accrued interest to pay 36422.22 is calculated, which interest rate it is applied? also how interest deduction inc. reclaim tax 88254.83 is derived?

    Hi,
    to answer your first question, accrued interest interest to pay (or the Update type 'SE8702') is calculated based on the amount, the coupon rate applicable (in your case 2.1160 if I read it correctly), the period between the last coupon payment date (in your case 15.09.2014) and the current bond purchase date (in your case 16.11.2014) and finally the number of days in a year (depending on the interest rate method applicable).
    regarding the second question - I would guess interest deduction inc. reclaim tax or the Update type 'SE3006' is generated as a result of the Flow type '0306' and as the Flow category is 'Other Flow/ Condition', it is just entered manually.
    hope this will help you.
    Kind regards,
    Renatas

Maybe you are looking for

  • How/where can I download Acrobat Standard 9 Edition

    People, Anyone knows where can I download Adobe Acrobat Standard 9 Edition? Thanks JT

  • Error e_adept_resource_does_not_exist

    I have downloaded ADE and it appears to be opening and working ( no books to try) but when i try to download purchased book i get an error error xmlus = http://ns.adobe.com/adept data = "e_adept_resource_does_not_exist http://174.129.224.52/fulfillme

  • Macbook core 2 duo hard drive space.

    My first post here. Loving my new Macbook. I purchased a refreshed black mb two weeks ago. It comes with 80g hard drive. Out of the box, there approximately 73g available for use. No problem. Thursday I went to the Apple Store to upgrade to the new c

  • What is an invalid leaf count?

    My computer wasn't starting up and it was just going to the page with the apple and clock thing that kept spinning. I ran disk utility. It repaired one volume, but it said that when it checked my extended attributes file, I had an invalid leaf record

  • Tax classification fields are not appeared in master data

    Dear Experts, I searched the forum about my issue but i did not get any solution. I am not able to see the tax classification fields in customer master and material master.Even i assigned Country IN to JLST and JCST condition types by T-code OVK1. FY