107k views
4 votes
In this chapter, you learned that although a double and a decimal both hold floating-point numbers, a double can hold a larger value.

Write a C# program named DoubleDecimalTest that declares and displays two variables—a double and a decimal.

User Cusspvz
by
4.3k points

1 Answer

3 votes

Answer:

The DoubleDecimalTest class is as follows:

using System;

class DoubleDecimalTest {

static void Main() {

double doubleNum = 173737388856632566321737373676D;

decimal decimalNum = 173737388856632566321737373676M;

Console.WriteLine(doubleNum);

Console.WriteLine(decimalNum);

}

}

Step-by-step explanation:

Given

See attachment for complete question

Required

Program to test double and decimal variables in C#

This declares and initializes double variable doubleNum

double doubleNum = 173737388856632566321737373676D;

This declares and initializes double variable decimalNum (using the same value as doubleNum)

decimal decimalNum = 173737388856632566321737373676M;

This prints doubleNum

Console.WriteLine(doubleNum);

This prints decimalNum

Console.WriteLine(decimalNum);

As stated in the question, the above program will fail to compile because the decimal value is out of range.

To ensure that the program runs well, it's either the decimal value is reduced to within its range or it is comment out of the program.

In this chapter, you learned that although a double and a decimal both hold floating-example-1
User Elsni
by
4.2k points