浮点型float
Posted skyzy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了浮点型float相关的知识,希望对你有一定的参考价值。
浮点型float
class float(object):
float(x) -> floating point number
Convert a string or number to a floating point number, if possible.
def as_integer_ratio(self):
获取改值的最简比
float.as_integer_ratio() -> (int, int)
Return a pair of integers, whose ratio is exactly equal to the original
float and with a positive denominator.
Raise OverflowError on infinities and a ValueError on NaNs.
>>> (10.0).as_integer_ratio()
(10, 1)
>>> (0.0).as_integer_ratio()
(0, 1)
>>> (-.25).as_integer_ratio()
(-1, 4)
def conjugate(self, *args, **kwargs):
Return self, the complex conjugate of any float.
def fromhex(self, string):
将十六进制字符串转换成浮点型
float.fromhex(string) -> float
Create a floating-point number from a hexadecimal string.
>>> float.fromhex(‘0x1.ffffp10‘)
2047.984375
>>> float.fromhex(‘-0x1p-1074‘)
-4.9406564584124654e-324
def hex(self): 返回当前值的 16 进制表示
float.hex() -> string
Return a hexadecimal representation of a floating-point number.
>>> (-0.1).hex()
‘-0x1.999999999999ap-4‘
>>> 3.14159.hex()
‘0x1.921f9f01b866ep+1‘
def is_integer(self, *args, **kwargs):Return True if the float is an integer.
def __abs__(self):
x.__abs__() <==> abs(x)
def __add__(self, y):
x.__add__(y) <==> x+y
def __coerce__(self, y):
x.__coerce__(y) <==> coerce(x, y)
def __divmod__(self, y):
x.__divmod__(y) <==> divmod(x, y)
def __div__(self, y):
x.__div__(y) <==> x/y
def __eq__(self, y):
x.__eq__(y) <==> x==y
def __float__(self):
x.__float__() <==> float(x)
def __floordiv__(self, y):
x.__floordiv__(y) <==> x//y
def __format__(self, format_spec):
float.__format__(format_spec) -> string
Formats the float according to format_spec.
def __getattribute__(self, name):
x.__getattribute__(‘name‘) <==> x.name
def __getformat__(self, typestr):
float.__getformat__(typestr) -> string
typestr must be ‘double‘ or ‘float‘. This function returns whichever of
‘unknown‘, ‘IEEE, big-endian‘ or ‘IEEE, little-endian‘ best describes the
format of floating point numbers used by the C type named by typestr.
def __getnewargs__(self, *args, **kwargs):
def __ge__(self, y):
x.__ge__(y) <==> x>=y
def __gt__(self, y):
x.__gt__(y) <==> x>y
def __hash__(self):
x.__hash__() <==> hash(x)
def __init__(self, x):
def __int__(self):
x.__int__() <==> int(x)
def __le__(self, y):
x.__le__(y) <==> x<=y
def __long__(self):
x.__long__() <==> long(x)
def __lt__(self, y):
x.__lt__(y) <==> x<y
def __mod__(self, y):
x.__mod__(y) <==> x%y
def __mul__(self, y):
x.__mul__(y) <==> x*y
def __neg__(self):
x.__neg__() <==> -x
@staticmethod # known case of __new__
def __new__(S, *more):
T.__new__(S, ...) -> a new object with type S, a subtype of T
def __ne__(self, y):
x.__ne__(y) <==> x!=y
def __nonzero__(self):
x.__nonzero__() <==> x != 0
def __pos__(self):
x.__pos__() <==> +x
def __pow__(self, y, z=None):
x.__pow__(y[, z]) <==> pow(x, y[, z])
def __radd__(self, y):
x.__radd__(y) <==> y+x
def __rdivmod__(self, y):
x.__rdivmod__(y) <==> divmod(y, x)
def __rdiv__(self, y):
x.__rdiv__(y) <==> y/x
def __repr__(self):
x.__repr__() <==> repr(x)
def __rfloordiv__(self, y):
x.__rfloordiv__(y) <==> y//x
def __rmod__(self, y):
x.__rmod__(y) <==> y%x
def __rmul__(self, y):
x.__rmul__(y) <==> y*x
def __rpow__(self, x, z=None):
y.__rpow__(x[, z]) <==> pow(x, y[, z])
def __rsub__(self, y):
x.__rsub__(y) <==> y-x
def __rtruediv__(self, y):
x.__rtruediv__(y) <==> y/x
def __setformat__(self, typestr, fmt):
float.__setformat__(typestr, fmt) -> None
typestr must be ‘double‘ or ‘float‘. fmt must be one of ‘unknown‘,
‘IEEE, big-endian‘ or ‘IEEE, little-endian‘, and in addition can only be
one of the latter two if it appears to match the underlying C reality.
Override the automatic determination of C-level floating point type.
This affects how floats are converted to and from binary strings.
def __str__(self):
x.__str__() <==> str(x)
def __sub__(self, y):
x.__sub__(y) <==> x-y
def __truediv__(self, y):
x.__truediv__(y) <==> x/y
def __trunc__(self, *args, **kwargs):Return the Integral closest to x between 0 and x.
以上是关于浮点型float的主要内容,如果未能解决你的问题,请参考以下文章
JavaScript 中的所有数据都是以 64 位浮点型数据(float) 来存储。浮点型数据使用注意事项
正确生成浮点型的方法,解决sqlachemy Float浮点型的坑,生成float类型时,长度和精度均为0,导致查询不到结果!