python float to string n decimals
float = 2.154327
format_float = "{:.2f}".format(float) # change .2f to n digits you want
print(format_float)
python float to string n decimals
float = 2.154327
format_float = "{:.2f}".format(float) # change .2f to n digits you want
print(format_float)
python decimal to 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')
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us