0

I've seen examples of the terms "float" and "double" being applied to different scenarios and seem to understand that bits and bytes serve some role, but I cannot find a clear explanation of what the difference is. Memory constraints seem like the cause of such differentiation (??), but I really just want to know specifically what one is vs. the other.

Further, how does one tell if data is classified (or should be stored) as "float" vs. "double"?

How do these concepts apply to decimal values (vs. binary)?


Context: I have a series of variables stored in a .csv table for which I'm trying to define "storage type." Some are integers, others are strings and still others are numbers with decimals. I'm just trying to figure out how to define "storage type" for each.

theforestecologist
  • 4,667
  • 5
  • 54
  • 91
  • 3
    Possible duplicate of [Difference between float and double](http://stackoverflow.com/questions/2386772/difference-between-float-and-double) – Paul R Oct 04 '16 at 18:59
  • For those so quick to downvote, please either let me know what is wrong with the question, or spend a bit of extra time to help those (me) understand something you deem simple. – theforestecologist Oct 04 '16 at 19:01
  • Not my down-vote, but most likely you're getting down-voted due to apparent lack of any prior research effort and the fact that there are numerous duplicates of this question already on StackOverflow. Anyway, see the linked duplicate above - that pretty much covers everything in your question (and more). – Paul R Oct 04 '16 at 19:02
  • I've done a bunch of searching: Wikipedia, google searching, stackoverflow searches, but all responses (including the one you linked) specify applied examples. I'm specifically curious how to identify whether a number I'm looking at is float or double -- is it simply just based on the number of decimal places??? – theforestecologist Oct 04 '16 at 19:05
  • @PaulR: by the way, I changed my search terms on stackoverflow 5 times and the question you linked never came up on the first page... – theforestecologist Oct 04 '16 at 19:06
  • 1
    What do you mean *"a number I'm looking at"*? What language are you using? What operations are you performing? What precision do you need? – jonrsharpe Oct 04 '16 at 19:07
  • @theforestecologist: you might find this WIkipedia entry helpful: https://en.wikipedia.org/wiki/IEEE_754-1985 - IEEE-754 defines the size, range and precision of single and double precision (float and double) in the first couple of paragraphs. – Paul R Oct 04 '16 at 19:09
  • @Johnsharpe: I have a .csv file that contains a series of different 'variables.' Each variable is either an integer, a string, or a floating point number. I need to define the "storage type" of each floating point number. So I'm not using any language or performing any operations; nor am I concerned bout the precision. I just want to know how to define/describe the storage type of the numbers as they are written and saved in this .csv file. – theforestecologist Oct 04 '16 at 19:10

1 Answers1

3

Floating point is a way to represent numbers that is used in computers, and is explained elsewhere, for example here and here. Double just uses more bits than float, so double has more precision and range.

In a CSV file, numbers are stored as text, for example using the five characters "27.37". Floating point is a way of representing numbers that is used internally by computers, so the numbers you have in your CSV file are not floating-point numbers at all. They are neither floats nor doubles.

When these numbers are to be processed by a computer, the text format is (typically) converted to an internal format, usually one of float and double. You can't decide which by looking at the text version of the number, since it in itself is neither. You have to decide based on the precision and speed you need. In most cases I would recommend to use double, since doubles have higher precision, and are very fast on typical modern computers. You can save some space, and sometimes gain some speed, by using float, but that is only needed in exceptional cases.

But, to contradict myself: In some cases you can look at a number written as text, and determine whether it can be stored as a float or a double. For example, if you find the number "0.333333333333333314829616256247390992939472198486328125" written just like that, it isn't a float or a double in itself, but this particular number, with all those decimals, can be stored as a double but not as a float. If stored as a float, with its fewer bits, it would be converted to "0.3333333432674407958984375".

Community
  • 1
  • 1
Thomas Padron-McCarthy
  • 27,232
  • 8
  • 51
  • 75