从double转换为十进制 [英] cast from double to decimal

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

问题描述

       这可能是一个愚蠢的问题,但我无法施法,它一直告诉它不能表现,我知道  你通过将
放在你想要在括号前面使用的类型来投射一个值。对于double glassArea到decimal,它应该是(decimal)glassArea对吗?

        This is probably a silly question but i am having trouble casting it keeps telling that it cant perform, I know You cast a value by putting the type you want used in parenthesis just in front of it. For double glassArea to decimal it should be (decimal) glassArea right?

            int windowCost;

            int windowCount;

            int totalCost;

            decimal windowAreaCharge;



$
            windowCost = 0;

            windowCount = 0;

            totalCost = 0;

            windowAreaCharge = 9.49m;



$
           双倍宽度;

           双倍高度;

            double woodLength;

            double glassArea;

            string widthString;

            string heightString;

            string windowString;

$


            //读入宽度

            Console.WriteLine("Plase输入以米为单位的宽度。");

            widthString = Console.ReadLine(); //从用户那里获取价值

            width = double.Parse(widthString); //将字符串转换为doubele



            //读入高度

            Console.WriteLine("请输入以米为单位的高度。");

            heightString = Console.ReadLine();

            height = double.Parse(heightString);



            //计算(width.I + height)* 2 * 3.25并转换为英尺

            woodLength = 2 *(宽+高)* 3.25;

            // calculare width times height

            glassArea =(宽* 3.25)*(高* 3.25);



            //打印它
            Console.WriteLine("木头的长度是"+ woodLength +"foot");

            Console.WriteLine("玻璃的面积是"+ glassArea +"sqaure feet");



            Console.WriteLine("你想要多少个窗口?");

            windowString = Console.ReadLine();

            int.Parse(windowString);
$


            //计算(玻璃面积* windowAreaCharge)

            windowCost = glassArea * windowAreaCharge; 

           int windowCost;
            int windowCount;
            int totalCost;
           decimal windowAreaCharge;


            windowCost = 0;
            windowCount = 0;
            totalCost = 0;
            windowAreaCharge = 9.49m;


            double width;
            double height;
            double woodLength;
            double glassArea;
            string widthString;
            string heightString;
            string windowString;


            // read in the width
            Console.WriteLine("Plase enter the width in meters.");
            widthString = Console.ReadLine(); // get the value from the user
            width = double.Parse(widthString); //convert the string into a doubele

            // read in the height
            Console.WriteLine("Please enter the height in meters.");
            heightString = Console.ReadLine();
            height = double.Parse(heightString);

            // calculate (width.I + height) *2*3.25 and convert to feet
            woodLength = 2 * (width + height) * 3.25;
            //calculare width times height
            glassArea = (width * 3.25) * (height * 3.25);

            //print it
            Console.WriteLine("The length of the wood is " + woodLength + " feet ");
            Console.WriteLine("The area of the glass is " + glassArea + " sqaure feet ");

            Console.WriteLine("How many windows do you want?");
            windowString = Console.ReadLine();
            int.Parse(windowString);

            //calculate (area of glass * windowAreaCharge)
            windowCost = glassArea * windowAreaCharge; 

推荐答案

这是一个int。试试这个:

it's an int. Try this:

windowCost = (int)(glassArea * (double)windowAreaCharge);

问候,克里斯


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

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