Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python decimal string

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

Python Decimal

from decimal import Decimal
>>> Decimal('1.2')
Decimal('1.2')
Comment

Python Decimal

>>> (1.1 + 2.2) == 3.3
False
Comment

PREVIOUS NEXT
Code Example
Python :: django permission required 
Python :: set form field disabled django 
Python :: extend a class python 
Python :: python for loop even numbers 
Python :: Python Creating string from a timestamp 
Python :: mutable and immutable in python 
Python :: Python cheat sheet pdf download 
Python :: python simple input popup 
Python :: how to print two lists side by side in python 
Python :: plt opacity hist 
Python :: path of current working directory with os module python 
Python :: date object into date format python 
Python :: django template date format yyyy-mm-dd 
Python :: time a line of code python 
Python :: what is imageTk in pil python 
Python :: difference between object and class in python 
Python :: tkinter yes no dialogue box 
Python :: python get attributes of class 
Python :: dataframe drop rows by column value 
Python :: changing the current working directory in python 
Python :: how to check if a cell is empty in openpyxl 
Python :: python get item from queue 
Python :: example of django template for forms 
Python :: __call__ python 
Python :: python chrome 
Python :: convert dict to string python 
Python :: wget command python 
Python :: in pandas how to start an index from a specific number 
Python :: pandas pad method 
Python :: matplotlib custom legend 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =