Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Java in General
double and float loosing precision - java core knowledge
Joined: Mar 05, 2002
Jun 23, 2005 01:58:00
double adouble = 50.12333; System.out.println(adouble); adouble = adouble - 50; System.out.println(adouble); System.out.println("float ----------------------"); float afloat = 50.12333f; System.out.println(afloat); afloat = afloat - 50f; System.out.println(afloat);
The output of this program is:
Can anyone explain these values? I would expect no loss of precision with such small values!
Joined: Oct 12, 2000
Jun 23, 2005 04:15:00
value doesn't matter when you're dealing with floating point arithmetic. There's no magical number after which suddenly you start to loose precision, no magic formula that will tell you if and if so how much precision will be lost at any point.
It is sorta covered in the
JavaRanch Style Guide
subject: double and float loosing precision - java core knowledge
iterating a double
float * double...newbie question
Problem with DecimalFormat
Precision and scale of a decimal value
Keyboard.Class/Anyone with brains.pt2
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013