0

In my app I have a field that accepts numbers with 2 decimal places only. I want to cast this float number to a double, so would that cause any precision loss even though I am only working with 2 decimal places? Thanks!

Georgi Angelov
  • 4,338
  • 12
  • 67
  • 96
  • 4
    Casting from a `float` to a `double` might reveal imprecision that was already present, but it will never lose data. – Louis Wasserman Apr 10 '14 at 16:53
  • possible duplicate of [Convert float to double without losing precision](http://stackoverflow.com/questions/916081/convert-float-to-double-without-losing-precision) – Sionnach733 Apr 10 '14 at 16:54
  • @LouisWasserman, I will only be dealing with numbers consisting of max 2 decimal places. Would that still be able to cause imprecisions? – Georgi Angelov Apr 10 '14 at 16:55
  • 3
    Neither float nor double stores numbers with "decimal places," since they are stored in binary. You cannot represent e.g. `0.1` exactly as a binary fraction. If you want to store decimal numbers exactly, you must use `BigDecimal`. – Louis Wasserman Apr 10 '14 at 16:56

0 Answers0