Loss of precision - int -> float or double

后端 未结 9 1537
小蘑菇
小蘑菇 2020-11-27 15:22

I have an exam question I am revising for and the question is for 4 marks.

\"In java we can assign a int to a double or a float\". Will this ever lose

9条回答
  •  南方客
    南方客 (楼主)
    2020-11-27 16:14

    There are two reasons that assigning an int to a double or a float might lose precision:

    • There are certain numbers that just can't be represented as a double/float, so they end up approximated
    • Large integer numbers may contain too much precision in the lease-significant digits

提交回复
热议问题