Programming Fund-Extend Homework 05. Distance of the Stars
Колеги, мога ли да Ви помоля за малко помощ. Не мога да разбера, къде бъркам? Разликата в отговора е много малка
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
decimal proxima = 4.22M * 945000000000;
decimal milkyWay = 26000M * 9450000000000;
decimal radiusMilkyWay = 100000M * 9450000000000;
decimal distanceEarth = 46500000000M * 9450000000000M;
Console.WriteLine(proxima.ToString("G3"));
Console.WriteLine(milkyWay.ToString("G3"));
Console.WriteLine(radiusMilkyWay.ToString("G3"));
Console.WriteLine(distanceEarth.ToString("G3"));
}
}
}
По този начин дава 100 от 100:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
decimal proxima = 4.22m * 9460000000000m;
decimal milkyWay = 26000M * 9450000000000m;
decimal radiusMilkyWay = 100000M * 9450000000000m;
decimal distanceEarth = 46500000000M * 9450000000000M;
Console.WriteLine(proxima.ToString("e2"));
Console.WriteLine(milkyWay.ToString("e2"));
Console.WriteLine(radiusMilkyWay.ToString("e2"));
Console.WriteLine(distanceEarth.ToString("e2"));
}
}
}
Можете ли да ми кажете защо като разменя полужението на множителите и отговорът е различен?
decimal earthToItsNearestStar = 4.22m*9450000000000m;
decimal toTheCenterOfOurGalaxy = 26000M* 9450000000000m ;
decimal diameterOfTheMilkyWay = 100000*9450000000000M;
decimal toTheEdgeOfTheUniverse = 46500000000M*9450000000000M;
Console.WriteLine(earthToItsNearestStar.ToString("e2"));
Console.WriteLine(toTheCenterOfOurGalaxy.ToString("e2"));
Console.WriteLine(diameterOfTheMilkyWay.ToString("e2"));
Console.WriteLine(toTheEdgeOfTheUniverse.ToString("e2"));
decimal earthToItsNearestStar = 9450000000000m * 4.22m;
decimal toTheCenterOfOurGalaxy = 9450000000000m * 26000M;
decimal diameterOfTheMilkyWay = 9450000000000M * 10000M;
decimal toTheEdgeOfTheUniverse = 9450000000000M * 46500000000M;
Console.WriteLine(earthToItsNearestStar.ToString("e2"));
Console.WriteLine(toTheCenterOfOurGalaxy.ToString("e2"));
Console.WriteLine(diameterOfTheMilkyWay.ToString("e2"));
Console.WriteLine(toTheEdgeOfTheUniverse.ToString("e2"));