Can I use double instead of float? As it is more easy. Will that affect grading?

  • What makes you think it's "more easy" to use a double?
    – Air
    Jul 18 '14 at 15:14

I cannot speak for grading, perhaps someone else could answer that. Technically speaking, yes you can use a double wherever you use a float. While there may be no practical difference in the real world, there may be reasons why you might not want to do this:

  1. Generally the course teaches about choosing the right variable type for the task. For example, while you could store a char using an int it is generally discouraged. This probably carries over to other types as well. I imagine the instructors would be looking to see that you understand the differences between the types. In the auto-graded assignments this may not be an issue.
  2. The double type uses twice the amount of memory as a float, and usually also takes slightly longer for the CPU to process compared to a float. These differences are really tiny, and only noticeable when you have many variables or are performing many calculations. Again, I expect the instructors would be looking to see that you understand this added cost, and use the simplest type to perform the task.
  3. You might not necessarily be gaining anything by using a double. If you can trace the source of the value in the variable, it may be coming from a float any way. Assigning a float to a double does not gain any precision, as the information is not there to begin with.

Lastly, there may be times when you do actually need to use a double, in which case a float would be a mistake. A programmer needs to understand when this difference is important and choose the correct variable type.

I personally have not seen any occasion in the course which would benefit from either the magnitude or precision gained by using a double, but I may be mistaken.

  • I get It double use more bits than float, I always keep forgetting that. thank You
    – Rajat
    Jul 18 '14 at 12:18

Can I use double instead of float?

Yes, you can!

As it is more easy

Well, this has nothing to do with easiness. A double has double the precision and the size as a float. A double has a size of 8 bytes and can have up to ~15 digits after the decimal point while a float has a size of 4 bytes and can have up to ~7 digits.

Will that affect grading?

No, it won't!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .