MIDP - Float, Double - missing? Workaround?

Hi
i tried to use float or double in my first J2ME Project but it doesn't seem to work (although the compiler compiles the source throwing no exception, the application fails to run..).
I had a look at the MIDP 1.0 specification and think i found that float and double are not supported. Is taht really true?
If so, it seems a little bit strange to me, because these are basic primitiv data types that have a wide usage field.
In fact, i need to deal with floating point values in my J2ME, so, if there is noting like float or double, what could i do? Is there any workaround (only one i see is to store the 'float' as an 'extended' integer?
Thanks for your help,
josh

hi...
J2ME does not support floatting point (means both float and double) yet however you can cheack this site for alternative solution:
http://wireless.java.sun.com/midp/ttips/fixpoint/
or you want to download a good math float emulator for it (for free) at:
http://www.jscience.net/
:-)

Similar Messages

  • Float/double implementation

    I am writing an application in J2ME and badly need a float/double data type, which J2ME does not have. I was wondering if anybody had some good ideas on how to implement a float/double data type using only ints.
    Thanks.
    AnjuM

    Use 2 longs, one for the 1's and one for the deciamal part. if the decimal part is over the max number you want to represent in decimal then subtract max from it and add 1 to the 1's side.
    If I wanted to show 9 decimal places, then anything past 999,999,999 should have 1,000,000,000 subtracted from it and 1 added to the left side.

  • Setting precision value of float/double

    Hi,
    I am retrieving data from database in to a float/double datatye. when i display the value it is showing the decimal of 4 to 5.(ex:4325.65785) but i want to display it as (ex:4235.65).
    Thanks
    Gopi

    import java.text.DecimalFormat;
    public class FormatTest
         public static void main(String[] args)
              DecimalFormat df = new DecimalFormat("##0.00");
              double d = 123456.2345678;
              System.out.println("Formatted: " + df.format(d));

  • Float / Double Decimal Display

    How do you get a float or double to display a certain amount of decimal places?
    For example, dealing with money, to have it be displayed as $1.30 instead of $1.3

    Use NumberFormat class!
    A simple example:
    NumberFormat currency = NumberFormat.getNumberInstance();
    currency.setMinimumFractionDigits(2);
    currency.setMaximumFractionDigits(2);
    System.out.println(currency.format(AnyValue));

  • Float/double data types

    I use
    public void setId(float id) {this.id = id;}
    and
    setId(new Float(nodeNextTop.getChildNodes().item(0).getNodeValue()).floatValue());
    in my java files to get the value of a float which I want to display using
    <display:column align="center" sortable="true" nowrap="true" property="id" title="<%=id_%>" class="webText" />
    in my jsp file
    but it is displayed in true E format, ie, 1.123456789101112E15, I want to display the number as is, without the E, and it's beaten me, pls help.
    btw, double does the same

    top job, I'm learning something new each day, big thnx for the help

  • Screen mode with floating windows missing in Photoshop cs6?

    Hi,
    How can I show two images open in Photoshop CS6  - next to each other?
    Going through the screen modes by pressing F like in Photoshop CS5 doesn't get me there. That screen mode with the floating windows seems to be missing.
    I need it for comparisions and for dragging layers between the two images.
    Is the floating window screen mode achievable in CS6 or how else can I put two opened images next to each other on Photoshop's workspace?
    Thanks!

    Thanks!
    It's so amusing: you get a new version of Photoshop and one of your well-known features is not where it used to be. Immediately an ancient fear takes over that the feature might have gone away.
    Which is, of course, never happening. There's even "sharpen" and "sharpen more" available in Photoshop.
    Bottom line: the new way of doing things are actually even better. You just need to pull the images off their tabs.

  • JDev 9.0.3.3 - float/double in the debugger

    Hello!
    I use JDeveloper ver. 9.0.3.3 and during last debug session I noticed one strange behaviour in the JDev debugger.
    There is a variable of type float with value of 10964.17. I see the value when I do System.out.println() of the variable. But the debugger show me value of 10964.2 !!!
    It seems like the debugger rounds the value. Also, I noticed the same behaviour with doubles too.
    What you think about it?
    I'll try to prepare a short test for the issue - when I'll have time for it.

    No need to prepare the test. I can reproduce it easily from your description.
    It only happens when debugging with OJVM. I've entered bug #3455484.
    Sorry for the bug.
    Thanks for the report.
    -Liz Looney

  • ProC cannot insert float/double C datatype

    Hallo,
    we compiled our C-Programms which we developed on SCO OpenServer
    with the ProC on Linux.
    Like on SCO we use the LANG enviroment variable de_DE for
    german national language support. If we try now this C-Code:
    setlocale(LC_ALL, "");
    double x = 2.34;
    EXEC SQL INSERT INTO anytable VALUES (:x);
    EXEC SQL COMMIT;
    (The table anytable has one column with number(10,4) )
    The result is that the value in table is only 2 instead of
    2,34 (german decimal separator is ,).
    If we try setlocale(LC_ALL, "C") the value in the table is
    correct 2,34.
    But we have to use the german national language
    support with setlocale(LC_ALL, "") for other purposes.
    So is it a bug or did we miss something.
    (On SCO it works with setlocale(LC_ALL, "");)
    Thanks !
    Reinhold Berger
    null

    i think you need to debug your code, lookalike the values you trying insert already exist in the database.
    these two IDs (6323df8a-5c57-4d3e-a477-09aa8b66100a, 7ae114df-9d52-4b08-affa-8c544cbc27b6).
    i would try to run the select command against the content db.
    SELECT TOP *  FROM [DB Name].[dbo].[NavNodes] where id = '6323df8a-5c57-4d3e-a477-09aa8b66100a'
    Please remember to mark your question as answered &Vote helpful,if this solves/helps your problem. ****************************************************************************************** Thanks -WS MCITP(SharePoint 2010, 2013) Blog: http://wscheema.com/blog

  • Float - double == loss of accuracy?  why?

    The following test fails:
    public void testFloat() {
            float number = 46702.45F;
            Float numberAsFloat = new Float(number);
            double numberAsDouble = numberAsFloat.doubleValue();
            System.out.println(numberAsDouble);
            assertTrue(46702.45 == numberAsDouble);
    }I probably just don't understand floating point data types or something, but I was very surprised that this test fails. If someone could enlighten me on WHY this fails, I would really appreciate it. For what it's worth, the value printed out for numberAsDouble was 46702.44921875 which I find entirely unexpected considering I am going from a lower precision data type (float) to a higher precision data type (double).

    Remember: the floating point representations (float and double) store binary values. Not decimal. The decimal values are parsed by the compiler and turned into floats and doubles in binary.
    The said binary values are approximations to the decimal values. Sometimes the binary and the decimal values coincide, but some times they don't.
    Floats have less precision than doubles.
    The binary string that represents that number, in a float, will be interpreted differently in a double, because the double has those additional bits of precision.
    Consider this code:
        double nd = 46702.45d;
        float nf = 46702.45F;
        long ndl = Double.doubleToLongBits(nd);
        long nfl = Float.floatToIntBits(nf);
        long nfl2 = Double.doubleToLongBits(nf);
        System.out.println(Long.toBinaryString(ndl));
        System.out.println(Long.toBinaryString(nfl));
        System.out.println(Long.toBinaryString(nfl2));It prints this:
    100000011100110110011011100111001100110011001100110011001100110
    1000111001101100110111001110011
    100000011100110110011011100111001100000000000000000000000000000
    // now I add spaces to line up the various segments
    // sign   exponent  mantissa
         1 00000011100  110110011011100111001100110011001100110011001100110
         1    00011100  1101100110111001110011
         1 00000011100  110110011011100111001100000000000000000000000000000Look at that string of "0011"'s on the version of the number created as a double.
    Compare it to the 0's in the version that was created as a float and used as a double.

  • Float/double confusion

    Could someone explain the theory behind the following:
    The default floating point data type is a double, hence the following declaration will not compile:
    float f=1.3;
    However the following declaration will compile:
    float f=1/3
    ...without specifying that it should be a float. Why does this happen, and why is the resulting value in f 0.0? Surely it should be 0.3333 or similar?

    1/3 is the integer 1 divided with the integer 3, and since they both are integers it would be natural for the result to be integer too, and so the division performed is called integer division. And the integer 0 is the result because one third is doesn't fit any integer. The fractional part is clamped. This result is then implicitely casted to produce the float 0.0f.
    Why? Because that's the way it goes in C and C++.

  • Float & double variables

    I need to calculate money values, and was wondering how you get the float or double value to return only two characters after the decimal point?!

    Using float or double is not the best way for
    handling money. You may loose some....
    What about using BigDecimal?
    http://www.javaworld.com/javaworld/jw-06-2001/jw-0601-
    cents.htmlActually, he's probably converting money types (like dollars to pounds or whatever), and the teacher probably doesn't care about that minute error in calculation.
    But yeah, it's like my comp-arch teacher said. "If I have ten million dollars in the bank, and every second I add in my interest for that second, how much money do I have a year later?"

  • Float double big problem

    New to java.
    Heres a perplexing issue:
         private Float lengthInFeet;
         private Integer lengthInInches;
         public void calcLengthInFeet()     
              lengthInFeet = lengthInInches * 1.0 / 12.0;
    compile error:
    incompatible types
    found : double
    required: java.lang.Float
    lengthInFeet = lengthInInches * 1.0 / 12.0;
    What am I doing wrong?
    Thanks,
    sb
    ^

    You are mixing primitive types and class types.
    You need to know the difference.
    To create a new Float object, you have to use the new operator.
    Try reading the section on variable types in the online tutorial:
    http://java.sun.com/docs/books/tutorial/java/nutsandbolts/variables.html
    You can also fix this single problem by changing the class types to primitive types, like this:
    private double lengthInFeet;
    private int lengthInInches;However, unless you learn/understand the distinction between the types, you won't get much farther. Read the tutorial.
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Adobe Reader Read Mode Floating Toolbar Missing Page Numbers

    How do I get the page numbers to show up in the Read Mode toolbar.
    Mine are missing.
    I Googled it for a while and wasn't able to find anything.

    Could it be related to a group policy setting?

  • Simple Math Actions ( float, double... )

    Hi guys, does anybody could help me with those
    simple calculations ?
    Take a look at next code:
    public class CMainApp {
    public static void main(String[] args) {
    float f1, f2 ;
    f1 = 1.2f ;
    f2 = 3f ;
    f1 = f1 * f2 ;
    // Why returned value couldn't be
    // 3.6 ???
    System.out.println( f1 ); // PAY ATTENTION !!! : 3.6000001
    }//main
    }//CMainApp
    For some reason I got strange answers 3.6000001. It should be 3.6.
    Is there any way to deal with this problem ?
    Thanks a lot, Mark. If you could, please mail me at
    mailto:[email protected]

    JohanUP, first thanks for respond.
    But you solution dosn't serve my needs.
    // This code line will print you 4
    // but I wants my 3.6
    System.out.println( Math.round( 1.2 * 3 ) );
    Now I'm trying some tricks with NumberFormat, If I'll
    success I'll let you guys to know.

  • A problem using doubles/floats

    i have an applet with 4 radio buttons and 5 check boxes! when i click on some (mix and match) the value on the text field sometimes goes like this 8.8888889 etc, and other times it is like 2.34! how can i change that 8.88889 to be displayed as 2.34! i have tried changing the value in the code, but that solves the problem but then a diff combination does the same thing! :(

    But anyway, since we're in this thread now...
    The short version is that there are a finite number of values that can be stored in a float or double, but there are infinitely many float/double values in the real numbers in the range between he min value and max value. So a lot of numbers are going to be aproximations.
    Why is a "simple" number like, say, 0.9, not exact, you ask? Java's VM (and pretty much all modern computer hardware) stores floating point number in base-2, not base ten. So if you look at the bits, and you see "1" in the first position after where the binary-point (base-2 equivalent of a decimal point) would be, that doesn't mean 1/10, it means1/2. So "0.5" in decimal (base-10) is the same as "0.1" in binary (base-2). What's "0.1" base-10 in base-2? Don't know off the top of my head, but it's a repeating fraction, just like 0.3333333... for 1/3 (which, in base-3, is 0.1, exactly).
    For more details, see:
    http://docs.sun.com/source/806-3568/ncg_goldberg.html

Maybe you are looking for