×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

How to get the hexadecimal value of a float number in python?

Python | find hexadecimal value of float value: Here, we are going to learn how to find a hexadecimal value of a given float value? Submitted by IncludeHelp, on April 03, 2019

Hexadecimal value of a float number

To get the hexadecimal value of a float number we use – float.hex() method, it accepts a float value and returns its hexadecimal value in string format.

Syntax

float.hex(number)

Parameter(s)

number – a float value to be converted into hexadecimal.

Return value

str – it returns hexadecimal value of number in string format.

Example

Input:
num = 10.23
    
print("hex value of ", num, " is = ", float.hex(num))
    
Output:
hex value of  10.23  is =  0x1.475c28f5c28f6p+3

Python code to get hexadecimal value of given float number

# python code to demonstrate example
# of float.hex() function

num = 0.0
print("hex value of ", num, " is = ", float.hex(num))

num = 10.23
print("hex value of ", num, " is = ", float.hex(num))

num = -10.23
print("hex value of ", num, " is = ", float.hex(num))

Output

hex value of  0.0  is =  0x0.0p+0
hex value of  10.23  is =  0x1.475c28f5c28f6p+3
hex value of  -10.23  is =  -0x1.475c28f5c28f6p+3
Advertisement
Advertisement

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.