使用 NSNumberFormatter

发布于 2024-09-04 06:27:25 字数 733 浏览 1 评论 0原文

我有一个问题正在寻找答案。我不太了解 NSNumberFormatter。我盯着文档看了一会儿,似乎无法理解为什么我根本无法让 setMinimum (或 setMaximum)工作。

这是我正在使用的代码:

NSNumberFormatter* numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[numberFormatter setMinimum:[NSDecimalNumber decimalNumberWithString:@"2"]];
[numberFormatter setMaximum:[NSDecimalNumber decimalNumberWithString:@"2"]];
[numberFormatter setMultiplier:[NSNumber numberWithDouble:1]];
//[numberFormatter setMaximumFractionDigits:OVER9000];
NSLog(@"%@, %@", [numberFormatter stringFromNumber:[NSNumber numberWithDouble:1.123456789]], [numberFormatter stringFromNumber:[NSNumber numberWithDouble:0.8]]);

我一直在玩类似的东西,我的计划是会发生一些事情,但它看起来确实没有发生任何事情(即在控制台中,我得到 1, 1 )...

I have a question that I am looking for the answer to. I am not really understanding NSNumberFormatter. I've stared at the documentation for a while, and can't seem to understand why I can't get setMinimum (or setMaximum) to work at all.

Here is the code I am using:

NSNumberFormatter* numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[numberFormatter setMinimum:[NSDecimalNumber decimalNumberWithString:@"2"]];
[numberFormatter setMaximum:[NSDecimalNumber decimalNumberWithString:@"2"]];
[numberFormatter setMultiplier:[NSNumber numberWithDouble:1]];
//[numberFormatter setMaximumFractionDigits:OVER9000];
NSLog(@"%@, %@", [numberFormatter stringFromNumber:[NSNumber numberWithDouble:1.123456789]], [numberFormatter stringFromNumber:[NSNumber numberWithDouble:0.8]]);

I've been playing around with stuff like that and my plan was that something would happen, but it really doesn't look like anything is going on (i.e. in the console, I get 1, 1)...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月亮是我掰弯的 2024-09-11 06:27:25

因为您实际上并没有问问题,所以这里有一个关于 NSNumberFormatter

下次提出问题,您可以获得更多帮助。

Since you didn't actually ask a question here's a link about NSNumberFormatter

Next time ask a question and you can get more help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文