Determine precision and scale of particular number in Python

后端 未结 9 1915
野的像风
野的像风 2020-12-09 21:04

I have a variable in Python containing a floating point number (e.g. num = 24654.123), and I\'d like to determine the number\'s precision and scale values (in t

9条回答
  •  無奈伤痛
    2020-12-09 21:32

    I think you should consider using the decimal type instead of a float. The float type will give rounding errors because the numbers are represented internally in binary but many decimal numbers don't have an exact binary representation.

提交回复
热议问题