Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python get string from decimal

from decimal import Decimal
import json

# Get the string from the decimal
string = json.dumps(str(Decimal('3.000')))
print(f'{string = }') # string = "3.000"

# Get string without quotation marks
plain_number = string[1:-1]
print(f'{plain_number = }') # plain_number = 3.000

# Get string from decimal without json
simple_string = str(Decimal('3.200'))
print(f'{simple_string = }') # simple_string = 3.200

# Load string into decimal
dec = Decimal(json.loads(string))
print(f'{dec = }') # dec = Decimal('3.000')
Comment

get decimal number from string python

import re
re.findall("d+.d+", string)
Comment

PREVIOUS NEXT
Code Example
Python :: python conditional operator one line 
Python :: tkinter messagebox 
Python :: python for else 
Python :: plt.imshow not showing image 
Python :: tf dropout 
Python :: orderd set in python 
Python :: make blinking text python1 
Python :: get one from dataloader 
Python :: assignment 7.1 python data structures 
Python :: how to check if an input is a string in python 
Python :: adding static file and its usage in Django 
Python :: change date format python code 
Python :: count the number of rows in a database table in Django 
Python :: read specific rows from csv in python 
Python :: pandas filter length of string 
Python :: pandas slicing from one column to another 
Python :: python: measure time code 
Python :: how to get the current year in python 
Python :: drop a row with a specific value of a column 
Python :: boto3 read excel file from s3 into pandas 
Python :: integer colomn to datetime pandas python 
Python :: check if dataframe contains infinity 
Python :: increase a date in python 
Python :: python logger get level 
Python :: python google chrome 
Python :: remove extra spaces python 
Python :: django static files / templates 
Python :: check where bool in a list python 
Python :: python how to check if a functions been called 
Python :: pandas change to numeric 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =