gpt4 book ai didi

ios - 将 1299 显示为 1.2K 而不是 1.3K

转载 作者:行者123 更新时间:2023-11-28 19:03:40 26 4
gpt4 key购买 nike

我的号码是 1299。

我要显示为1.2K

我在下面试过,但它给出的是 1.3K

int mLike 
NSString *mString = [NSString stringWithFormat:@"%d", mLike];
if (mLike>=1000) {
mString = [NSString stringWithFormat:@"%0.1fK", mLike*1.0/1000];
}
mString = [mString stringByReplacingOccurrencesOfString:@".0" withString:@""];
likeLabel.text = [NSString stringWithFormat:@"%@ LIKES", mString];

这给了我 1.3 K

知道如何将它设置为 1.2K 吗?

最佳答案

NSInteger mLike = 1301;
NSString *mString = [NSString stringWithFormat:@"%d", mLike];
if (mLike>=1000)
{
mLike = mLike - (mLike%100); // this was missing in your code. Subtract the remainder from the total inorder to get the desired result.
mString = [NSString stringWithFormat:@"%0.1fK", mLike*1.0/1000];
}
mString = [mString stringByReplacingOccurrencesOfString:@".0" withString:@""];
NSLog(@"%@",[NSString stringWithFormat:@"%@ LIKES", mString]);

关于ios - 将 1299 显示为 1.2K 而不是 1.3K,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22474938/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com