Float Methods

float.hex()

Express the stored floating-point value as hexadecimal significand times a power of two. Finite results include a hexadecimal prefix and a p exponent written in decimal. This permits exact round trips with float.fromhex(), including signed zero. Nonfinite values produce special strings; NaN payloads are not preserved. Unlike bytes.hex(), this represents a number, not a byte dump.

Formal Syntax & Structure

python syntaxpython
value.hex()

Return Value

str

Hexadecimal floating-point representation or special nonfinite spelling.

Working Example

Example Snippetpython
value = 6.5print(value.hex())print(float.fromhex(value.hex()))print((-0.0).hex())
Python Reference