“Python Decimal” Code-Antworten

Python 2 Dezimalstellen

print(format(432.456, ".2f"))

>> 432.45

print(format(321,".2f"))

>> 321.00
Wild Weasel

Python -Dezimalschnur

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')
YEP Python

Geben Sie die Antwort in 6 Dezimalpython

print("{:.6f}".format(variable_name))
Curious Cod

Fixe Präzisionsfloat -Python festgelegt

x = 13.949999999999999999
g = float("{:.2f}".format(x))
Cute Corncrake

Python Decimal

from decimal import Decimal
>>> Decimal('1.2')
Decimal('1.2')
Careful Caterpillar

Python Decimal

>>> (1.1 + 2.2) == 3.3
False
SAMER SAEID

Ähnliche Antworten wie “Python Decimal”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen