
3.2.3 Double
双精度浮点型(Double)也是一种数字类型,用于存储程序中的小数类型的数值。当程序中需要保存一个小数时,都可用Double类型,例如平均成绩、长度、宽度、金额等。
Double的存储范围是-1.79E+308~1.79E+308,如果要赋值的数据超出这个范围,程序就会报错。
【例3.8】使用Double变量完成求平均成绩的流程。假设一名同学的语文成绩是82分,数学成绩是67分,英语成绩是92分,计算该同学三门成绩的平均分并在Output面板输出。
具体实现步骤如下所示。
1)进入Studio界面,点击Process创建一个新流程,命名为3_8_Double,如图3-73所示。

图3-73 新建流程
2)拖入一个Sequence活动到设计器面板。在Properties面板中,将Sequence活动的DisplayName属性更改为“求三门平均成绩”,如图3-74所示。
3)在Variables面板中,点击Create Variable按钮创建变量AverageGrade,用于存储三门平均成绩。由于平均成绩可能为小数,应设置为Double型,打开Variable type下拉列表选择Browse for Types...选项,如图3-75所示。
4)系统随即会显示Browse and Select a .Net Type对话框,在Type Name字段中输入System.Double,在结果中选择需要的选项后点击OK按钮,如图3-76所示。

图3-74 拖入Sequence活动并更改属性

图3-75 创建变量

图3-76 设置变量类型为Double
5)此时Variables面板中变量AverageGrade的数据类型将会被更改为Double型,如图3-77所示。

图3-77 更改变量类型后的Variables面板
6)拖入一个Assign活动到“求三门平均成绩”活动中。在Properties面板中,将DisplayName属性更改为“计算平均成绩”,在To属性中输入变量AverageGrade,在Value属性中输入(82+67+92)/3,如图3-78所示。
7)拖入一个Write Line活动到“求三门平均成绩”活动中。在Properties面板中,将DisplayName属性更改为“输出平均成绩”,将Text属性更改为“"该同学的平均成绩是"+AverageGrade.ToString”,如图3-79所示。

图3-78 计算平均成绩

图3-79 输出平均成绩
8)按F5键执行流程,将在Output面板中显示执行结果,如图3-80所示。

图3-80 执行结果