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

python find digits in string with decimal

>>> import re
>>> re.findall("d+.d+", "variable name")
['13.4']
Comment

extract decimal number from string python

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

PREVIOUS NEXT
Code Example
Python :: get hours from datetime.timedelta in python (Django) 
Python :: data types in numpy array 
Python :: pygame template 
Python :: python dlib 
Python :: openpyxl 
Python :: basic flask api 
Python :: jupyter read excel 
Python :: Concatenating objects in pandas 
Python :: Maximize Difference codechef solution 
Python :: python program to demonstrate scoping 
Python :: python different types of loops 
Python :: embed python discord 
Python :: switch case python 3.10 
Python :: python check if false in dict 
Python :: python with example 
Python :: how to plot a pandas dataframe with matplotlib 
Python :: sorted python 
Python :: print string python 
Python :: repl.it install packages python 
Python :: Python Tkinter MenuButton Widget 
Python :: how to devided array into parts python 
Python :: python last index of item in list 
Python :: Python - How To Concatenate List of String 
Python :: fun games 
Python :: python using secrets 
Python :: random.randint(0,20) + pyrthon 
Python :: create tuples in pandas 
Python :: dictionary from two list 
Python :: escape brackets in regex python 
Python :: pyttsx3 saving the word to speak 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =