【问题标题】:Division not giving the expected result除法没有给出预期的结果
【发布时间】:2013-03-21 18:48:16
【问题描述】:

代码:

float cordsStepAmountHeight;
float cordsStepAmountWidth;

coordStepAmountHeight=(2.0f/height);
coordStepAmountWidth=(2.0f/width);

其中宽度为 2560,高度为 1504(我设备的分辨率)。

经过计算,coordStepAmountHeight 的值为 0.0013297872 是正确的 但 cordsStepAmountWidth 以 7.8125E-4 的形式出现(当我认为它应该是 0.00078125 时)

为什么 coordStepAmountWidth 会这样出现?是否与声明为浮点数的变量无法处理计算或其他原因有关?

【问题讨论】:

    标签: android floating-point division integer-division


    【解决方案1】:

    是同一个号码。就是所谓的浮点数的科学表示。你可以在这里阅读更多信息:http://www.learncpp.com/cpp-tutorial/25-floating-point-numbers/

    【讨论】:

    • 太棒了,这让我很困惑,为什么它们的表示方式不同。感谢您的回答。
    【解决方案2】:

    7.8125E-4 和 0.00078125 与 e-4 表示 x10^-4(除以 10000)相同。所以从数学的角度来看,它们是相同的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-29
      • 1970-01-01
      • 2019-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-09
      • 2021-01-06
      相关资源
      最近更新 更多