Determine precision and scale of particular number in Python

后端 未结 9 1919
野的像风
野的像风 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:36

    If you need to check precision, you can try:

    def prec_check(a,b)
      a = str(a)
      b = str(b)
      do = bool(True)
      n = 0
      while do == True:
        if a and b and a[n] == a[b]:
          n += 1
        else:
          do = false
      return n
    

提交回复
热议问题