• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / Python / Using Python to Convert Decimal to String

Using Python to Convert Decimal to String

August 26, 2022 Leave a Comment

To convert a decimal to a string in Python, you can use the Python str() function.

from decimal import Decimal

d = Decimal("1.23")

s = str(d)

print(d, type(d))
print(s, type(s))

#Output:
1.23 <class 'decimal.Decimal'>
1.23 <class 'str'>

When working with different variables in Python, the ability to easily be able to convert a variable into a variable with a different type is valuable.

One such case is if you want to convert a decimal into a string.

The Python decimal module provides support for fast correctly rounded decimal floating point arithmetic.

Sometimes it might make sense to want to convert a decimal into a string.

To convert a decimal to a string in Python, you can use the Python str() function.

Below is an example of how you can convert a decimal into a string using Python.

from decimal import Decimal

d = Decimal("1.23")

s = str(d)

print(d, type(d))
print(s, type(s))

#Output:
1.23 <class 'decimal.Decimal'>
1.23 <class 'str'>

Hopefully this article has been useful for you to learn how to convert a decimal variable into a string using Python.

Other Articles You'll Also Like:

  • 1.  Read Last Line of File Using Python
  • 2.  Python gethostbyname() Function – Get IPv4 Address from Name
  • 3.  How to Multiply Two Numbers in Python
  • 4.  Sort a List of Strings Using Python
  • 5.  Using Python to Check If a Number is a Perfect Square
  • 6.  How to Check If File is Empty with Python
  • 7.  How to Check if String Contains Lowercase Letters in Python
  • 8.  islower Python – Check if All Letters in String Are Lowercase
  • 9.  Using Python to Insert Item Into List
  • 10.  Get All Substrings of a String in Python

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy

x