将十进制转换为双精度 [英] Convert Decimal to Double

查看:183
本文介绍了将十进制转换为双精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用轨迹栏更改 Form 的不透明度。

I want to use a Track-Bar to change a Form's opacity.

这是我的代码:

decimal trans = trackBar1.Value / 5000;
this.Opacity = trans;

构建应用程序时,出现以下错误:

When I build the application, it gives the following error:


不能将类型十进制隐式转换为 double

我尝试使用 trans double ,但随后使用 Control 不起作用。这段代码在以前的VB.NET项目中运行良好。

I have tried using trans and double but then the Control doesn't work. This code worked fine in a past VB.NET project.

推荐答案

显式转换为 double 不必这样:

double trans = (double) trackBar1.Value / 5000.0;

将常数标识为 5000.0 (或 5000d )就足够了:

Identifying the constant as 5000.0 (or as 5000d) is sufficient:

double trans = trackBar1.Value / 5000.0;
double trans = trackBar1.Value / 5000d;

这篇关于将十进制转换为双精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆