gpt4 book ai didi

c# - 将 Math.Pow 转换为 float

转载 作者:太空宇宙 更新时间:2023-11-03 17:20:21 25 4
gpt4 key购买 nike

我正在尝试将 Math.Pow 转换为 float 类型,但 VS2013 告诉我“无法将类型‘double’隐式转换为‘float’。

我以为我在做类型转换如下:

private void COMBO_AWG_SelectedIndexChanged(object sender, EventArgs e)
{
float d = 0.0f;
int awg = int.Parse(COMBO_AWG.Text);
//MessageBox.Show(awg.ToString());
d = 0.127 * (92 * ((float)Math.Pow(36, awg) / 39));

TB_awg2mm.Text = d.ToString();
}

有什么想法吗?

最佳答案

正在将其转换为 float ,但您将该结果与 double 相乘,导致 double .

任何非整数且不以 f 为后缀的文字或 F被视为 double .

解决这个问题:

d = 0.127F * (92 * ((float)Math.Pow(36, awg) / 39));

注意 F0.127 之后.

关于c# - 将 Math.Pow 转换为 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24806568/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com