Converting Vector with Floats to float[] typecast error?

Java Developers,
I am able to convert my String vector to a
String[] but just can't get the Vector with Floats to be converted to a float[] array. I have looked into google and java.sun.com Forums but still cant seem to find the answer. I would really appreciate your help!
This is how I am making the conversion from Vector(String) to String[]:
legendLabelsArray = new String[columnHeads.size()];
int k=0;
Iterator e = columnHeads.iterator();
while(e.hasNext()){
System.out.println("inside the enumerator");
legendLabelsArray[k] = e.next().toString();
System.out.println("Array elements at " + k + " are " + legendLabelsArray[k]);
System.out.println(k++);
How can I make something similar to work with a Vector with Floats to float[] instead of Strings?
Thanks,
Musaddiq
[email protected]

Something like this ...
float[] floatArray = new float[vectorOfFloats.size()];
int k=0;
Iterator e = vectorOfFloats.iterator();
while(e.hasNext()){
floatArray[k] = ((Float) e.next()).floatValue();
k++;

Similar Messages

  • What's the best way to deal with floating point errors?

    What's the best way to deal with the decimal number errors in Flex?
    Lets say I have:
    var number1:Number = 1.1;
    var number2:Number = 1;
    var result:Number = number1 - number2;
    trace(result);
    I get "0.10000000000000009".
    What's the best way to deal with this so that i get the right result?
    Using the trick: result = Math.round( result * Math.pow(10,13) ) / Math.pow(10,13); is not useful as such when using big numbers.
    For example, If number1 = 100000000001.1, and number2 = 0.2, I get "100000000000.90001" as result. The previous rounding fixes rounding errors after 13th decimal, but here the first rounding errors come after 4 digits.
    The toPrecision method in Number and NumberFormatter dont seem be of use by themselves because of the same reason.
    So I'd have to check how big the number is, and then round the number based on that.
    So far I've constructed a method that does that with logarithms like this:
    public function floatFix(number:Number):Number{
          var precision:int = 14-Math.floor(Math.log(Math.abs(number))*Math.LOG10E);
          var precisionFactor:Number = Math.pow(10, precision);
          return Math.round(Number(number*precisionFactor))/precisionFactor;
    It just seems rather odd that one would have to create and use something like that to just count 1.1-1; There's a lot of calculating in that method, and i'm guessing that having to use that in a loop could slow down a program quite a bit.
    I think there really should be a pre-built method in flex for something like this, but I can't find any.
    Anyone know any better/faster ways?

    Use the application server database pooling services to create a datasource that can be access using JNDI.
    Move the database access code to a Servlet so that a JSP submits a form to the Servlet that does the database access and packages the data into a bean which is passed to another JSP to be displayed.

  • Conversion Vector of Floats to float[]:  exception?

    Java Developers,
    I am able to convert my String vector to a
    String[] but just can't get the Vector with Floats to be converted to a float[] array. I have looked into google and java.sun.com Forums but still cant seem to find the answer. I would really appreciate your help!
    This is how I am making the conversion from Vector(String) to String[]:
    legendLabelsArray = new String[columnHeads.size()];
    int k=0;
    Iterator e = columnHeads.iterator();
    while(e.hasNext()){
    System.out.println("inside the enumerator");
    legendLabelsArray[k] = e.next().toString();
    System.out.println("Array elements at " + k + " are " + legendLabelsArray[k]);
    System.out.println(k++);
    How can I make something similar to work with a Vector with Floats to float[] instead of Strings?
    Thanks,
    Musaddiq
    [email protected]

    Assuming Vector v with Float elements:
    float[] a = new float[v.size()];
    int n = 0;
    for (Iterator i = v.iterator(); i.hasNext(); )
        a[n++] = ((Float) i.next()).floatValue();

  • Designing for floating point error

    Hello,
    I am stuck with floating point errors and I'm not sure what to do. Specifically, to determine if a point is inside of a triangle, or if it is on the exact edge of the triangle. I use three cross products with the edge as one vector and the other vector is from the edge start to the query point.
    The theory says that if the cross product is 0 then the point is directly on the line. If the cross product is <0, then the point is inside the triangle. If >0, then the point is outside the triangle.
    To account for the floating point error I was running into, I changed it from =0 to abs(cross_product)<1e-6.
    The trouble is, I run into cases where the algorithm is wrong and fails because there is a point which is classified as being on the edge of the triangle which isn't.
    I'm not really sure how to handle this.
    Thanks,
    Eric

    So, I changed epsilon from 1e-6 to 1e-10 and it seems to work better (I am using doubles btw). However, that doesn't really solve the problem, it just buries it deeper. I'm interested in how actual commercial applications (such as video games or robots) deal with this issue. Obviously you don't see them giving you an error every time a floating point error messes something up. I think the issue here is that I am using data gathered from physical sensors, meaning the inputs can be arbitrarily close to each other. I am worried though that if I round the inputs, that I will get different data points with the exact same x and y value, and I'm not sure how the geometry algorithms will handle that. Also, I am creating a global navigation mesh of triangles with this data. Floating point errors that are not accounted for correctly lead to triangles inside one another (as opposed to adjacent to each other), which damages the integrity of the entire mesh, as its hard to get your program to fix its own mistake.
    FYI:
    I am running java 1.6.0_20 in Eclipse Helios with Ubuntu 10.04x64
    Here is some code that didn't work using 1e-6 for delta. The test point new Point(-294.18294451166435,-25.496614108304477), is outside the triangle, but because of the delta choice it is seen as on the edge:
    class Point
         double x,y;
    class Edge
         Point start, end;
    class Triangle
         Edge[] edges;
         public Point[] getOrderedPoints() throws Exception{
              Point[] points = new Point[3];
              points[0]=edges[0].getStart();
              points[1]=edges[0].getEnd();
              if (edges[1].getStart().equals(points[0]) || edges[1].getStart().equals(points[1]))
                   points[2]=edges[1].getEnd();
              else if (edges[1].getEnd().equals(points[0]) || edges[1].getEnd().equals(points[1]))
                   points[2]=edges[1].getStart();
              else
                   throw new Exception("MalformedTriangleException\n"+this.print());
              orderNodes(points);
              return points;
            /** Orders node1 node2 and node3 in clockwise order, more specifically
          * node1 is swapped with node2 if doing so will order the nodes clockwise
          * with respect to the other nodes.
          * Does not modify node1, node2, or node3; Modifies only the nodes reference
          * Note: "order" of nodes 1, 2, and 3 is clockwise when the path from point
          * 1 to 2 to 3 back to 1 travels clockwise on the circumcircle of points 1,
          * 2, and 3.
         private void orderNodes(Point[] points){
              //the K component (z axis) of the cross product a x b
              double xProductK = crossProduct(points[0],points[0], points[1], points[2]);
              /*        (3)
               *          +
               *        ^
               *      B
               * (1)+             + (2)
               *       ------A-->
               * Graphical representation of vector A and B. 1, 2, and 3 are not in
               * clockwise order, and the x product of A and B is positive.
              if(xProductK > 0)
                   //the cross product is positive so B is oriented as such with
                   //respect to A and 1, 2, 3 are not clockwise in order.
                   //swapping any 2 points in a triangle changes its "clockwise order"
                   Point temp = points[0];
                   points[0] = points[1];
                   points[1] = temp;
    class TriangleTest
         private double delta = 1e-6;
         public static void main(String[] args)  {
                    Point a = new Point(-294.183483785282, -25.498196740397056);
              Point b = new Point(-294.18345625812026, -25.49859505161433);
              Point c = new Point(-303.88217906116796, -63.04183512930035);
              Edge aa = new Edge (a, b);
              Edge bb = new Edge (c, a);
              Edge cc = new Edge (b, c);
              Triangle aaa = new Triangle(aa, bb, cc);
              Point point = new Point(-294.18294451166435,-25.496614108304477);
              System.out.println(aaa.enclosesPointDetailed(point));
          * Check if a point is inside this triangle
          * @param point The test point
          * @return     1 if the point is inside the triangle, 0 if the point is on a triangle, -1 if the point is not is the triangle
          * @throws MalformedTriangleException
         public int enclosesPointDetailed(LocalPose point, boolean verbose) throws Exception
              Point[] points = getOrderedPoints();          
              int cp1 = crossProduct(points[0], points[0], points[1], point);
              int cp2 = crossProduct(points[1], points[1], points[2], point);
              int cp3 = crossProduct(points[2], points[2], points[0], point);
              if (cp1 < 0 && cp2 <0  && cp3 <0)
                   return 1;
              else if (cp1 <=0 && cp2 <=0  && cp3 <=0)
                   return 0;
              else
                   return -1;
             public static int crossProduct(Point start1, Point start2, Point end1, POint end2){
              double crossProduct = (end1.getX()-start1.getX())*(end2.getY()-start2.getY())-(end1.getY()-start1.getY())*(end2.getX()-start2.getX());
              if (crossProduct>floatingPointDelta){
                   return 1;
              else if (Math.abs(crossProduct)<floatingPointDelta){
                   return 0;
              else{
                   return -1;
    }

  • Invalid Floating Point Error

    I have one Captivate 3 project published as a Stand Alone
    project with Flash 8 selected. There are 36 slides, no audio, no
    eLearning, SWF size and quality are high.
    One person who runs this gets an "Invalid Floating Point"
    error when he tries to run it the first time. He is running Windows
    XP SP2, Firefox 3.0.4. and Flash Player 10.0.12.36. Other Captivate
    projects I've created run fine for him. This one sometimes runs
    after the first Error message.
    Any thoughts on the cause and fix?
    Thanks,
    Janet

    iMediaTouch probably doesn't support Floating Point formats - it certainly doesn't mention them in the advertising. Try saving your files as 24-bit PCMs, and they should import fine.

  • Looking for VI where i can convert covert a float number to Q 11.5 representation

    looking for VI where i can convert covert a float number to Q 11.5 representation and what exactly  Q 11.5 representation means.
    Kindly help me on the same.
    Solved!
    Go to Solution.

    Appears to be right, but don't forget to round to the nearest integer.
    http://zone.ni.com/reference/en-XX/help/371361H-01/glang/round_to_nearest/
    Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
    If you don't hate time zones, you're not a real programmer.
    "You are what you don't automate"
    Inplaceness is synonymous with insidiousness

  • TLF 2/2.1/3 Weird behavior with floating graphics?

    Hi guys,
    I'm working on a chat application running on RED5 / AS3 and I'm struggling to get my client "UI" working perfectly.
    My problem is related to the TL Framework, on every version available.
    Basicly, I want to display a picture ( for user messages ) and icons ( for notifications ) on the left side of my lines, like this :
    So, I'v been messing around with "float=start", "float=left" and such, but i'm always encountering weird behaviors whenever I scroll or resize my containerController. It's quite easy to reproduce with the following code :
    public class Main extends Sprite
              private var controller:ContainerController;
              public function Main():void
                        if (stage) init();
                        else addEventListener(Event.ADDED_TO_STAGE, init);
              private function init(e:Event = null):void
                        stage.scaleMode = StageScaleMode.NO_SCALE;
                        stage.align = StageAlign.TOP_LEFT;
                        removeEventListener(Event.ADDED_TO_STAGE, init);
                        var holder:Sprite = new Sprite();
                        addChild( holder );
                        var tFlow:TextFlow = new TextFlow();
                        for ( var i:int = 0; i < 50; i++ )
                             tFlow.addChild( createLine() );
                        controller = new ContainerController( holder, 400, stage.stageHeight  );
                        tFlow.flowComposer.addController( controller );
                        tFlow.flowComposer.updateAllControllers();
                        stage.addEventListener( Event.RESIZE, resizeController );
              private function resizeController( e:Event ):void
                        controller.setCompositionSize( 400, stage.stageHeight );
                        controller.textFlow.flowComposer.updateAllControllers();
              public function createLine( ):DivElement
                        var d:DivElement;
                        var p:ParagraphElement;
                        var im:InlineGraphicElement = new InlineGraphicElement();
                        im.source = new Bitmap( new BitmapData( 16, 16, true, 0x30FF0000 ) ); // 0x30 Alpha
                        im.float = "left";
                        d = new DivElement();
                        d.clearFloats = "both";
                        p = new ParagraphElement();
                        d.addChild( p );
                        p.addChild( im );
                        return d;
    Basicly, I'm stacking 50 transparent "floating" elements. It works fine most of time, but if I randomly resize my Flash Player Window, I can get the first "invisible" element to overlap the last "visible" :
    It seems to be happening right when the last "floating" element should disappear. Instead, it gets "over" the previous one. It happens upon container resize and scrolls. I'v encountered this issue on lastest 2, 2.1 and 3 TLF builds.
    Beside the visual "bug", it also screws up my container.getContentBounds().height calls - which can make scrolling "trembling", as the height gets reajusted.
    I'm running out of ideas about how to handle this. This bug appears whenever I use "floating" graphics and I can't think of any other way to display graphics on the left side of my chat-lines.
    Maybe someone ran into this very problem and figured out a way to make it work?
    Excuse my english, thanks in advance,
    Lionel.

    Thank you for your report. And I have found the root cause.
    In BaseCompose.as
    protected function composeFloat(elem:InlineGraphicElement, afterLine:Boolean):Boolean
    if (!floatFits && (_curParcel.fitAny || _curParcel.fitsInHeight(totalDepth, int(logicalFloatHeight))) && (!_curLine || _curLine.absoluteStart == floatPosition || afterLine))
                    floatFits = true;
    The condition of if is true, only when the weird behavior happens. We need to discuss about how to fix it.

  • Precision with float and double values

    Hi, does anyone knows how can i get more precise calculations with floating point numbers? Let's see an example:
    public class Teste {
    public static void main(String args[]) {
    float i = 0;
    while (i<=10) {
    System.out.println(i);
    i=i+0.1f;
    /* output
    0.0
    0.1
    0.2
    0.3
    0.4
    0.5
    0.6
    0.70000005
    0.8000001
    0.9000001
    1.0000001
    1.1000001
    1.2000002
    1.3000002
    1.4000002
    1.5000002
    1.6000003
    1.7000003
    1.8000003
    1.9000003
    2.0000002
    2.1000001
    2.2
    2.3
    2.3999999
    2.4999998
    2.5999997
    2.6999996
    2.7999995
    2.8999994
    2.9999993
    3.0999992
    3.199999
    3.299999
    3.399999
    3.4999988
    3.5999987
    3.6999986
    3.7999985
    3.8999984
    3.9999983
    4.0999985
    4.1999984
    4.2999983
    4.399998
    4.499998
    4.599998
    4.699998
    4.799998
    4.8999977
    4.9999976
    5.0999975
    5.1999974
    5.2999973
    5.399997
    5.499997
    5.599997
    5.699997
    5.799997
    5.8999968
    5.9999967
    6.0999966
    6.1999965
    6.2999964
    6.3999963
    6.499996
    6.599996
    6.699996
    6.799996
    6.899996
    6.9999957
    7.0999956
    7.1999955
    7.2999954
    7.3999953
    7.499995
    7.599995
    7.699995
    7.799995
    7.899995
    7.9999948
    8.099995
    8.199995
    8.299995
    8.399996
    8.499996
    8.599997
    8.699997
    8.799997
    8.899998
    8.999998
    9.099998
    9.199999
    9.299999
    9.4
    9.5
    9.6
    9.700001
    9.800001
    9.900002
    */

    http://forum.java.sun.com/thread.jsp?forum=31&thread=357174

  • Converting string to float

    I have a decimal string "122339994" which i am trying to convert to float using Float.parseFloat. This results in incorrect value of 1.22339992E8.
    I thought for floats precsision comes into effect after decimal places.
    public static void main(String[] args) {
    String floatString = "122339994";
    float floatNumber = Float.parseFloat(floatString);
    System.out.println("Float is "+floatNumber+". Now double "+Double.valueOf(floatString));
    }

    See this API
    [Java2SE Float|http://download-llnw.oracle.com/javase/6/docs/api/java/lang/Float.html#valueOf%28java.lang.String%29]
    Note that trailing format specifiers, specifiers that determine the type of a floating-point literal (1.0f is a float value; 1.0d is a double value), do not influence the results of this method. In other words, the numerical value of the input string is converted directly to the target floating-point type. In general, the two-step sequence of conversions, string to double followed by double to float, is not equivalent to converting a string directly to float. For example, if first converted to an intermediate double and then to float, the string
    "1.00000017881393421514957253748434595763683319091796875001d"
    results in the float value 1.0000002f; if the string is converted directly to float, 1.0000001f results.
    Its better to see the Java APIs first for any information, we will get almost all the information we need from APIs
    Regards,
    Venkatesh

  • Smart Forms : problem with Float Variable

    Hi  Expert,
       I have a probelm with Float variable. In my smart forms one fields of table QAMV contain value like 8.0000000000000000E+01.
    I have to remove the exponent and display value like 80.
    I have tried wa_qamv-sollwert(E10.4).. but it not working.
    Can U suggest me some solution.
    Regards
    Swati.
    Edited by: Swati Namdev on Apr 27, 2010 12:19 PM

    Hi,
    Please follow the steps.
    1. In your smart form create a variable w_val ,, type,, associate type -->  CHAR10
    2. Now write a code, jsut above your node where u wud like to get this value... For this Create -> Flow Logic -> Program Lines.. Now you have editor..
    3. In input parameters , put i_tab-QAMV.. and in output parameter put w_val... and Code like below
    CALL FUNCTION 'MD_CONV_QUANTITY_FLOAT_TO_PACK'
      EXPORTING
        iv_menge       = i_tab-qamv
      IMPORTING
        EV_MENGE       = w_val.
    4. Now grag and drop this w_val from global data field list...your this w_val will have the rounded value.. Pls try this and check..   It will work.
    Regards,
    Lokesh.
    Edited by: Lokesh Tarey on Apr 27, 2010 9:28 AM

  • Draw line with float values possible

    Hi,
    Using Canvas drawing is possible to draw line with float values.
    graphics.drawLine(int,int,int,int);
    graphics.drawLine(float,float,float,float);Thanks and regards,
    Rakesh.

    not possible
    graphics.drawLine(float,float,float,float);...there's no such method in MIDP API: [click here for javadoc of Graphics class methods|http://java.sun.com/javame/reference/apis/jsr118/javax/microedition/lcdui/Graphics.html#drawLine(int,%20int,%20int,%20int)]

  • JSlider with Floating point values

    I desperatly need to create a JSlider with floating/decimal values. For example between 0 and 1 and ticks within an interval of 0.1.
    The default behaviour of JSlider doesn't allow me to do so, hence is there any other way around ? I know it's possible to programmatically handle the required calculation by divding the values by 10, 100 or anything, but i want to display the actual values (floating/decimal) on the JSlider bar.
    Thanks in advance

    this might do you for the display
    import javax.swing.*;
    import java.awt.*;
    class JSliderLabels extends JFrame
      public JSliderLabels()
        setLocation(400,200);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        JSlider slider = new JSlider(0, 100, 1);
        slider.setMajorTickSpacing(25);
        slider.setPaintTicks(true);
        java.util.Hashtable labelTable = new java.util.Hashtable();
        labelTable.put(new Integer(100), new JLabel("1.0"));
        labelTable.put(new Integer(75), new JLabel("0.75"));
        labelTable.put(new Integer(50), new JLabel("0.50"));
        labelTable.put(new Integer(25), new JLabel("0.25"));
        labelTable.put(new Integer(0), new JLabel("0.0"));
        slider.setLabelTable( labelTable );
        slider.setPaintLabels(true);
        JPanel jp = new JPanel();
        jp.add(slider);
        getContentPane().add(jp);
        pack();
      public static void main(String[] args){new JSliderLabels().setVisible(true);}
    }

  • Convert string to floating-point

    Hi all,
    ..very basic question, but I tryed it for hours and only received short-dumps
    <b>How can I convert a string into a floating-point number?</b>
    Kind regards,
    Stefan

    hi
    try this
    to convert  string to float.
    data : a type f,
    s type string value '1.023'.
    a = s.
    write :/ a.
    to convert float to string.
    data : a type f value '1.023',
    s type string.
    s = a.
    write : s.

  • Draw fct with float

    Does someone know why all draw fonction like drawArc, drawLine use int instead of float or double? it would not be more precise to draw with float or double?
    thx

    fonction? LOL!
    Seriously though, the method you want is java.awt.Graphics2D.draw(Shape) and fill(Shape). You would use it like this:
    protected void paintComponent(Graphics g) {
      Graphics2D g2 = (Graphics2D) g;  // cast required to get Graphics2D functionality
      // Now make a shape, any shape
      Shape shape = new Rectangle2D.Double(2.5, 3.0, 30.0, 40.0);
      g2.setColor(Color.yellow);
      g2.fill(shape);
      g2.setColor(Color.black);
      g2.draw(shape);
    }Hope this helps.

  • Error occurred while converting the file ".." An unknown error occurred -50

    I've had a few tracks which seem to skip on my ipod but play perfectly fine on itunes.
    As a result, I've been converting these tracks to ACC files; this has worked for a few files but for one particular album i get the following:
    +error occurred while converting the file ".." An unknown error occurred -50+
    I've tried renaming the files, I re-created my playlist but nothing works.
    Thanks in advance.

    *Skipping songs*
    The iPod seems to fail to play all of the occasional track that iTunes, and indeed other PMPs, are happy to play. There is probably some minor technical error in the internal structure of the file which is normally ignored by other playback software but causes the Classic to bail out.
    You may like to try scanning the files with MP3 Validator which can find & fix some internal MP3 errors.
    Some users have also suggested that completely removing all id3 tags and then replacing the information can be a solution. This can be achieved in iTunes by selecting an affected track, right/option clicking and using the option Convert id3 tags > None. Since some files may mistakenly have more than one tag you may need to repeat this action. Once you have confirmed that no tag is present you can replace the tag information using Convert id3 tags > V2.3 (I believe it is recommended to avoid using V2.4).
    Personally I have found files for which these solutions don't work. In this case the workaround is either to re-rip the tracks or get iTunes to re-encode the file, e.g. convert AAC to MP3 or vice versa and sync the newly encoded file to the iPod instead. Because transcoding will cause a loss of fidelity you should keep your original file so that if a future iPod firmware resolves this issue you can put your original files back onto the iPod.
    tt2

Maybe you are looking for