如何强制执行表达式的评估类型为双重
我如何确保表达式始终将其评估为双重评估,即使它没有双重,我都会遇到此网站 https://lealen.microsoft.com/en-en-us/dotnet/csharp/csharp/language-reganp/language-reference-reference-reference-reference/builtin-reference/builtin-types/浮动点数 - 型,它说:
因此,我该如何覆盖这个问题并确保表达式始终被评估为双重,
我试图使用逃离图书馆,并且每当我将其放在其中(4/3)中时,它将其作为一个整数,甚至不是浮子,这都破坏了整个计算,因此我必须解决这个问题,
如果我尝试使用以下表达式
(4.0/3)或(4/3.0)或(4/3.0)= 1.333333 故障案件如下 (4/3)= 1 希望我的解释很清楚
how could I make sure that the expression is always evaluated as a double even if it has no double in it, I came across this website https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/floating-point-numeric-types, It says :
so how can I override this problem and make sure that the expression is always evaluated as a double,
I am trying to use the library of Flee, and whenever I put a fraction in it like(4/3) it deals with it as an integer, not even a float, this ruins the whole calculation so I have to get around this problem,
If I try and use the following expression it works
(4.0/3) or (4/3.0) = 1.33333
the faulty case is as follows
(4/3) = 1
hopefully my explanation is clear
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如文档中所述,这是该语言的特征。您始终可以将分子或分母施放成浮子或双double,该浮点数将以相同类型的结果结尾:
As mentioned in the docs, that is a feature of the language. You can always cast either the numerator or the denominator into a float or double which will end with a result of the same type:
我设法通过强迫逃离图书馆不再将任何给定的输入视为整数来解决问题,我通过编写以下代码来做到这一点:
祝大家好运
I managed to solve the problem by forcing Flee Library to not consider any given input as Integer anymore, I did that by writing the following code:
Best of luck to you all
解决方案1
使用双重注释,该注释告诉编译器该数字实际上是双重的
(D double,也适用于Float使用F)
解决方案2
使用明确的铸造
Solution 1
Use the double annotation which tells to the compiler that the number is actually a double
(d for double, also works for float using f)
Solution 2
Use explicit casting