Click here to Skip to main content
15,919,245 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
if the input is 65.790, then the output will be 65.790, 65, and A.

What I have tried:

using System;
using static System.Console;

namespace ConsoleApp08
{
class Program
{
static void Main(string[] args)
{
double aNumber;
WriteLine("Please input a number.");
aNumber = Convert.ToDouble(ReadLine());
WriteLine($"Your number as a double:{aNumber}");
aNumber = Convert.ToInt32(aNumber);
WriteLine($"Your number as an int:{aNumber}");
aNumber = Convert.ToChar(aNumber);
WriteLine($"Your number as a char:{aNumber}");


}
}
}
Posted
Updated 28-Jan-22 6:00am
v2
Comments
Richard MacCutchan 28-Jan-22 11:34am    
You have declared aNumber as a Double type, so you cannot store an integer or a character into it.
Jay Katariya 28-Jan-22 11:37am    
Yes, how to get 3 decimal in double as output?
Richard MacCutchan 28-Jan-22 11:40am    
You cannot store an integer in a double type.

A double cannot convert into char. Try the following code:
double aNumber, bNumber;
char charNo;
Console.Write("Please Input a Number:");
aNumber = Convert.ToDouble(Console.ReadLine());
bNumber = Math.Truncate(aNumber);
charNo = Convert.ToChar((int)bNumber);
Console.WriteLine("Result " + aNumber + "," + bNumber + "," + charNo);
 
Share this answer
 
This is a duplicate of your question at Use the appropriate method of the convert class[^]. Please do not repost.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900