Example 1: Using str() method
my_float=1234.56 #Float
float_to_string=str(my_float)
print(type(my_float))
print(type(float_to_string))
print(float_to_string)
Output:
<class 'float'>
<class 'str'>
1234.56

Example 2: using format() method
my_float=1234.56 #Float
float_to_string=format(my_float,'f')
print(type(my_float))
print(type(float_to_string))
print(float_to_string)
Output:
<class 'float'>
<class 'str'>
1234.560000

Example 3: Using format string
my_float=1234.5678
float_to_string=f"{my_float:.4f}"
print(type(my_float))
print(type(float_to_string))
print(float_to_string)
Output:
<class 'float'>
<class 'str'>
1234.5678

-
Have Questions? Post them here!
More Posts related to Python,
- Comments in Python Programming
- tkinter - Hello World! Program
- How to install Python 3.11 on Mac
- Python matplotlib segmentation fault: 11 macOS Big Sur
- Change label (text) color in tkinter
- Python Hello World! Program with code example (snippet)
- Calculate discount amount python code
- Take input argument from command line in Python Programming
- How to pip install Python Modules in VSCode
- Tkinter - add x and y padding to label text
- Python raise error with message example
- Check if String Contains a Substring - Python
- Python Program To Calculate Simple Interest (SimpleInterest.py)
- What does b prefix before a String mean in Python?
- What is Terminal Velocity and its Formula? How to calculate it programmatically?
- How to List all Packages installed using pip [Python]
- Convert Float to String in Python
- Change the background of Tkinter label or text
- How to Install Python Modules in VS Code
- Indent Python code in Notepad++
- Validate email address in Python using regular expression (regex)
- Python: Fix command not found pip or pip3 on zsh shell
- TypeError: must be str, not int [Fix Python]
- ModuleNotFoundError: No module named qdarkstyle.colorsystem [Python]
- Python - Convert float to String
More Posts:
- FCM Messages! Testing Notifcation from Microsoft to investigate this problem [Microsoft Teams] - Microsoft
- incorrect line ending: found carriage return (\r) without corresponding newline (\n) - Android
- Drag drop files here option missing for SharePoint document library - SharePoint
- Lost your iPhone? Regenerate QR Code for Microsoft Authenticator App - Microsoft
- Cannot access files within Microsoft Teams - We are setting up your file directory - Teams
- Java 8: Steam map with Code Examples - Java
- Install Apache Tomcat ver 8 on Mac OS X Yosemite 10.10 - Mac-OS-X
- Java JDBC Connection with Database using SSL (https) URL - Java