Results 1 to 4 of 4
Thread: Put float value to double
- 09-18-2008, 11:44 AM #1
Member
- Join Date
- Sep 2008
- Posts
- 1
- Rep Power
- 0
Put float value to double
Hi,
I want to put a float value to double variable.
float f = 1.0000345f;
double d = f;
System.out.println("float " + f);//Prints 1.0000345
System.out.println("double " + d);//Prints 1.0000344514846802
Why does the double variable contains a different value.
Is there a way to overcome this issue.
Thanks,
Chamal.
- 09-18-2008, 12:15 PM #2
Senior Member
- Join Date
- May 2008
- Location
- Makati, Philippines
- Posts
- 234
- Rep Power
- 6
^_^ this may enlighten you
https://java.sun.com/docs/books/tuto...datatypes.html
float: The float data type is a single-precision 32-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion, but is specified in section 4.2.3 of the Java Language Specification. As with the recommendations for byte and short, use a float (instead of double) if you need to save memory in large arrays of floating point numbers. This data type should never be used for precise values, such as currency. For that, you will need to use the java.math.BigDecimal class instead. Numbers and Strings covers BigDecimal and other useful classes provided by the Java platform.
double: The double data type is a double-precision 64-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion, but is specified in section 4.2.3 of the Java Language Specification. For decimal values, this data type is generally the default choice. As mentioned above, this data type should never be used for precise values, such as currency.Mind only knows what lies near the heart, it alone sees the depth of the soul.
- 09-19-2008, 06:42 PM #3
-
Similar Threads
-
String to Float
By durahman in forum New To JavaReplies: 2Last Post: 02-12-2008, 12:17 AM -
Float to String
By mew in forum New To JavaReplies: 4Last Post: 12-29-2007, 05:08 PM -
type mismatch: cannot convert from double to float
By bugger in forum New To JavaReplies: 2Last Post: 11-16-2007, 01:24 PM -
Help with valid declarations of a float
By baltimore in forum New To JavaReplies: 1Last Post: 07-31-2007, 10:28 AM -
Class float
By Peter in forum New To JavaReplies: 1Last Post: 07-08-2007, 01:17 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks