gpt4 book ai didi

objective-c - 如何在 Objective-C 的 NSTextField 中组合 char 和 int?

转载 作者:行者123 更新时间:2023-12-03 17:54:19 25 4
gpt4 key购买 nike

例如,我有以下代码,其中 lblPercentNSTextField:

double Progress = progress( Points);
[lblPercent setIntValue:(Progress)];

我将其设置为整数值,因此它会丢弃小数,因为由于某种原因,NSProgressIndicator 强制我使用 double 值。无论如何,在进度条旁边的标签中,我希望它看到数字 x%,旁边有百分号。

我尝试了标准串联技术,但没有成功。

最佳答案

您应该使用 NSNumberFormatter with the percent style

NSNumberFormatter* formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle: NSNumberFormatterPercentStyle];
// Any other format settings you want
NSString* formattedNumber = [formatter stringFromNumber: [NSNumber numberWithDouble: progress]];

关于objective-c - 如何在 Objective-C 的 NSTextField 中组合 char 和 int?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16172370/

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