无法显示所有十进制数字C#

问题描述 投票:1回答:1

我在C#中有一个小方法,目的是解决这个[[基本方程:

Base equation

我是手动给

n和x

我们将假定

X

的值为3,而n的值为1。如果我评估方程式,则会得到以下结果:enter image description here我的问题是输出为0,

我也尝试解析结果

,但仍为0。实际结果是

0.88888888

,但是在程序输出中我刚得到了0这是我的代码:

using System; namespace Polinomio { class Program { static void Main(string[] args) { int x = 3; int n = 1; double result = 0; for (int i = 0; i <= n; i++) { result += (double)(Math.Pow((x - 1) / 3, Math.Pow(2, i))) / Math.Pow(2, i); } Console.WriteLine(result); } } }

我不知道我做错了什么或我想念什么,我将提供任何帮助。
c# parsing math double
1个回答
1
投票
只需将变量的数据类型更改为双精度。

double x = 3; int n = 1;

这将解决问题。
© www.soinside.com 2019 - 2024. All rights reserved.