Answers for "print python definig decimal"

3

print upto 1 decimal place python

print("{:.1f}".format(number)) # Python3
print "%.1f" % number          # Python2
Posted by: Guest on June-06-2020
3

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')
Posted by: Guest on April-23-2022
2

python print with 2 decimals

# round a value to 2 decimal points
value_to_print = 123.456
print(f'value is {round(value_to_print, 2)}')
# prints: value is 123.46
Posted by: Guest on May-06-2020

Python Answers by Framework

Browse Popular Code Answers by Language