Float Methods

float.fromhex()

Parse hexadecimal floating-point text. The coefficient uses hexadecimal digits and the optional p exponent uses decimal digits to indicate a power of two. Leading and trailing whitespace, optional sign and optional 0x prefix are supported. At least one coefficient digit is necessary for a finite numeric spelling. Infinity and NaN spellings are accepted. Invalid syntax raises ValueError, out-of-range large finite results raise OverflowError, and very small values can round to zero.

Formal Syntax & Structure

python syntaxpython
float.fromhex(s, /)

Parameters & Attributes

NameTypeDescription
sstrHexadecimal floating-point text or supported nonfinite spelling.

Return Value

float

Floating-point value parsed from hexadecimal text.

Working Example

Example Snippetpython
print(float.fromhex("0x1.ap2"))print(float.fromhex("  -0X1.8P+1  "))print(float.fromhex("10"))
Python Reference