Python 3 in Visual Studio

2019-08-28 04:54发布

Hi there I am a newbie to Python, could someone help me how to convert an input string to ZAR (South African Rand) in order to produce the R symbol before the float amount the user enters? Example: R400.00

Assistance will be highly appreciated.

标签: python
1条回答
三岁会撩人
2楼-- · 2019-08-28 05:46

There is no special format for currency in standard library. You can organize output formatting like that:

zar = float(input("ZAR="))
print('R{:.2f}'.format(zar))

but in finance calculations better use Decimal not float.
Or - create own class ZAR() with special method __str__() if You really need it )

查看更多
登录 后发表回答