Determine precision and scale of particular number in Python

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

    If you need to check the number of corresponding digits (of a and b)

    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
    

    Note that this doesn't work with the "Decimal" module.

提交回复
热议问题