Write a C# Sharp program to find the whole number and fractional part from a positive and a negative Decimal number, Double number

  • برمجة سي شارب
  • برمجة

Write a C# Sharp program to find the whole number and fractional part from a positive and a negative Decimal number, Double number. 
Expected Output:
Original Decimal Number: 52.7365
The whole number and fractional part of the said positive Decimal number:
52
0.7365
Original Decimal Number: -52.736
The whole number and fractional part of the said negative Decimal number:
-52
-0.736
Original Double Number: 92.73165
The whole number and fractional part of the said positive Float number:
92
0.731650000000002
Original Double Number: -42.7636
The whole number and fractional part of the said negative Float number:
-42
-0.763599999999997

الأجوبة

using System;
using System.Text;
namespace exercises {
  class Program {
    public static void Main() {
      decimal decimalNumber;
      decimalNumber = 52.7365m;
	  Console.WriteLine("Original Decimal Number: "+decimalNumber);
	  Console.WriteLine("The whole number and fractional part of the said positive Decimal number:");
      Console.WriteLine(Math.Truncate(decimalNumber));
	  Console.WriteLine(decimalNumber-Math.Truncate(decimalNumber));
      decimalNumber = -52.736m;
	  Console.WriteLine("Original Decimal Number: "+decimalNumber);
	  Console.WriteLine("The whole number and fractional part of the said negative Decimal number:");
	  Console.WriteLine(Math.Truncate(decimalNumber)); 
	  Console.WriteLine(decimalNumber-Math.Truncate(decimalNumber)); 
	  double floatNumber;
      floatNumber = 92.73165;
	  Console.WriteLine("Original Double Number: "+floatNumber);
	  Console.WriteLine("The whole number and fractional part of the said positive Float number:");
      Console.WriteLine(Math.Truncate(floatNumber));
	  Console.WriteLine(floatNumber-Math.Truncate(floatNumber));
      floatNumber = -42.7636;
	  Console.WriteLine("Original Double Number: "+floatNumber);
	  Console.WriteLine("The whole number and fractional part of the said negative Float number:");
	  Console.WriteLine(Math.Truncate(floatNumber)); 
	  Console.WriteLine(floatNumber-Math.Truncate(floatNumber));
	}
  }
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...