About 92,400 results
Open links in new tab
  1. floating point - What is float in Java? - Stack Overflow

    In Java, when you type a decimal number as 3.6, its interpreted as a double. double is a 64-bit precision IEEE 754 floating point, while floatis a 32-bit precision IEEE 754 floating point. As a float is less precise than a double, the conversion cannot be performed implicitly.

  2. Float and double datatype in Java - Stack Overflow

    Dec 22, 2014 · For example, calculations such as square root, or transcendentals such as sine and cosine, result in a value whose precision requires a floating-point type. Java implements the standard (IEEE–754) set of floatingpoint types and operators.

  3. How can I convert integer into float in Java? - Stack Overflow

    Dec 7, 2010 · I have two integers x and y. I need to calculate x/y and as outcome I would like to get float. For example as an outcome of 3/2 I would like to have 1.5. I thought that easiest (or the only) way to...

  4. Manipulating and comparing floating points in java

    Jun 14, 2015 · In Java the floating point arithmetic is not represented precisely. For example this java code: float a ...

  5. How can I handle precision error with float in Java?

    first of Float is the wrapper class for the primitive float. and doubles have more precision . but if you only want to calculate down to the second digit (for monetary purposes for example) use an integer (as if you are using cents as unit) and add some scaling logic when you are multiplying/dividing. or if you need arbitrary precision use ...

  6. Representing float values in Java - Stack Overflow

    Jan 14, 2013 · Floating point literals in Java is a double value by default.. JLS 3.10.2 Floating-Point Literals. A floating-point literal is of type float if it is suffixed with an ASCII letter F or f; otherwise its type is double and it can optionally be suffixed with an ASCII letter D or d.

  7. formatting - How to print a float with 2 decimal places in Java ...

    Mar 29, 2010 · Below is code how you can display an output of float data with 2 decimal places in Java: float ratingValue = 52.98929821f; DecimalFormat decimalFormat = new DecimalFormat("#.##"); float twoDigitsFR = Float.valueOf(decimalFormat.format(ratingValue)); // output …

  8. What's wrong with using == to compare floats in Java?

    "for float fields, use the Float.compare method; and for double fields, use Double.compare. The special treatment of float and double fields is made necessary by the existence of Float.NaN, -0.0f and the analogous double constants; see the Float.equals documentation for details." (Joshua Bloch: Effective Java) –

  9. How to convert float to int with Java - Stack Overflow

    Mar 16, 2016 · If you want to convert a float value into an integer value, you have several ways to do it that depends on how do you want to round the float value. First way is floor rounding the float value: float myFloat = 3.14f; int myInteger = (int)myFloat; The output of this code will be 3, even if the myFloat value is closer to 4.

  10. What is the inclusive range of float and double in Java?

    Jun 5, 2012 · For example, the number 0.1 can be represented by 1 x 10-1, but there is no combination of base-2 exponent and mantissa that can precisely represent 0.1 -- the closest you get is 0.10000000000000001. So if you have an application where you are working with values like 0.1 or 0.01 a great deal, but where small (less than 0.000000000000001% ...

Refresh