在java中,如果确实需要,是否可以使用String.format仅显示小数?例如,如果我这样做:
String.format("%.1f", amount);
Run Code Online (Sandbox Code Playgroud)
它将格式化:"1.2222" - >"1.2""1.000" - >"1.0"等,
但在第二种情况下(1.000)我希望它只返回"1".这可能是String.format,或者我将不得不使用DecimalFormatter?
如果我必须使用小数格式化器,我是否需要为我想要的每种格式创建一个单独的DecimalFormatter?(最多1位小数,最多2位小数,等)
如果我有一个像这样的字符串:
"user1:type1,user2:type2,user3:type3"
Run Code Online (Sandbox Code Playgroud)
我想将其转换为元组列表,如下所示:
[('user1','type1'),('user2','type2'),('user3','type3')]
Run Code Online (Sandbox Code Playgroud)
我该怎么做呢?我是python的新手,但在文档中找不到一个很好的例子来做到这一点.
谢谢!