【问题标题】:Apfloat calculating trigonometric function wrong resultApfloat计算三角函数错误结果
【发布时间】:2018-10-27 20:06:12
【问题描述】:

我是 C# 开发人员,我有 UWP 应用程序,它可以使用 DecimalEx Nuget 包精确计算许多与数学相关的问题。我最近开始将我的应用程序移植到 Java 和 Android,我使用 Apfloat 作为替代方案(如果有更好的请推荐我)。我写了一个代码来计算三角函数,但结果比实际大 10 倍。这是我的代码示例:

            Apfloat degrees = new Apfloat(new BigDecimal(textbox1.getText().toString()), 20);
            Apfloat sin  = ApfloatMath.sin(degrees);
            Apfloat cos = ApfloatMath.cos(degrees);
            Apfloat tg = ApfloatMath.tan(degrees);
            Apfloat cotg = new Apfloat(1).divide(tg);
            Apfloat sec = new Apfloat(1).divide(cos);
            Apfloat csc = new Apfloat(1).divide(sin);

精度设置为 20。这是比较我的 C# 输出(在右侧是准确的)与 Java 输出的屏幕截图。

我也不知道如何在没有科学记数法的情况下显示结果。

提前谢谢你。 :)

【问题讨论】:

    标签: java android trigonometry apfloat


    【解决方案1】:

    原来只是格式问题,找到了解决方案。

    String.format("%#s", sin)
    

    等等;)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-13
      • 2015-04-05
      • 2013-07-23
      • 2015-09-28
      相关资源
      最近更新 更多