
この記事を三行にまとめると
端数切り捨て四捨五入
端数切り上げ
この記事は以下の動画の中に出てきたサンプルコードを載せたものです。コピペなどが必要なときに使ってください。
端数切り捨て
price = 198
tax = str(price)[:-1]
counts = list(range(price))
for i in range(int(tax)):
counts.append(i)
print('{}円の税込価格は{}円'.format(price, len(counts)))
四捨五入
price = 198
lists = list(str(price))
lists.insert(-1, '.')
tax = round(float(''.join(lists)))
counts = list(range(price))
for i in range(tax):
counts.append(i)
print('{}円の税込価格は{}円'.format(price, len(counts)))
端数切り上げ
price = 198
tax = str(price)[:-1]
counts = list(range(price))
for i in range(int(tax)):
counts.append('')
if str(price)[-1] != '0':
counts.append('')
print('{}円の税込価格は{}円'.format(price, len(counts)))