Jac*_*cob 18 c formatting cocoa objective-c
如何实现从double到字符串的以下转换:
1.4324 => "1.43"
9.4000 => "9.4"
43.000 => "43"
Run Code Online (Sandbox Code Playgroud)
即我想要舍入到小数位但不想要任何尾随零,即我不想要
9.4 => "9.40" (wrong)
43.000 => "43.00" (wrong)
Run Code Online (Sandbox Code Playgroud)
所以我现在使用的这段代码不起作用,因为它显示多余的零:
[NSString stringWithFormat: @"%.2f", total]
Run Code Online (Sandbox Code Playgroud)
Siv*_*hna 35
你弄错了.这将有效:
[NSString stringWithFormat: @"%.2lf", total]
Run Code Online (Sandbox Code Playgroud)