Wrox Programmer Forums
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 4th, 2008, 06:04 PM
Registered User
 
Join Date: Jan 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Double values

I'm having a hard time understanding the doubles, floats etc.

Are the values of (double) 1/2 and (double) (1/2) the same or are they different?

 
Old February 5th, 2008, 12:15 AM
jomet
Guest
 
Posts: n/a
Default

Hi,

different
(double) 1/2 => double of 1 divided by 2
(double) (1/2) => double of 1/2

I this case it will not generate much diff
but if 1/3(ex only .33333333333) rounding takes for precision then it matters.

# 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.

Cheers,


jomet.
---------------------------------------------
Once you start a working on something,
dont be afraid of failure and dont abandon it.
People who work sincerely are the happiest.





Similar Threads
Thread Thread Starter Forum Replies Last Post
double in binär walid C# 1 January 24th, 2007 03:23 PM
double bookings urbanaccess Access 1 January 18th, 2007 08:41 AM
double quotes MyronCope Classic ASP Basics 2 November 21st, 2006 09:31 AM
Double Quotes langer123 Classic ASP Basics 2 March 16th, 2005 06:22 PM
double to string? chris97b Visual C++ 4 September 23rd, 2003 02:34 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.