xcode 如何在iphone的浮点值中只显示小数点后的两位数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10600145/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:20:24 来源:igfitidea点击:
how to show only two digits after the decimal in float value in iphone
提问by user1392981
I have a float number i want that it should display only two digits after decimal like if its is 1.566666 it simply show 1.56
我有一个浮点数,我想要它应该只显示小数点后的两位数,就像它是 1.566666 它只显示 1.56
I am using this way for float in my code
我使用这种方式在我的代码中浮动
float ProfitForCerenia=costtoclient/markup;
float totalProfit=costtoclient-ProfitForCerenia;
回答by jimpic
I assume you want a NSString with your number:
我假设你想要一个带有你的号码的 NSString:
[NSString stringWithFormat:@"%.02f", floatVal];