【问题标题】:How to display divided numbers in UILabel iOS如何在 UILabel iOS 中显示除数
【发布时间】:2014-04-15 11:37:12
【问题描述】:

有 2 个名为“liter”和“kronor”的文本字段。用户将在此处输入两个带小数的数字。

我有一个标签,我想将“克朗”与“升”(克朗/升)分开。

- (IBAction)prischeck:(id)sender {
    float x=[_kronor.text floatValue];
    float y=[_liter.text floatValue];
    float z= x/y;
}

我做对了吗?

【问题讨论】:

  • 是的,这是正确的,你需要什么
  • 在这个网站上稍微搜索一下就会对你大有帮助。 stackoverflow.com/a/17515691/2834868
  • 您正在计算z,但没有对它做任何事情——结果只是丢失了。
  • 完全正确。我想在标签中显示 z
  • literpriset.text = [NSString stringWithFormat:@"%f", z];

标签: ios uilabel


【解决方案1】:
literpriset.text = [NSString stringWithFormat:@"%f", z];

或

literpriset.text = [NSString stringWithFormat:@"%f / %f = %f", x, y, z];

如果您还需要显示 x 和 y。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-24
    • 1970-01-01
    相关资源
    最近更新 更多