MadsKirkFoged / EngineeringUnits

Working with units made easy with automatic unit-check and converting between units
MIT License
41 stars 10 forks source link

Temperature conversion doesn't work #15

Closed haikal-arif closed 1 year ago

haikal-arif commented 2 years ago

I am using sharpfluids when i noticed this bug This is piece of code that i can isolate

static void Main(string[] args)
{
    var temperature = Temperature.FromDegreesCelsius(20);
    var pressure = Pressure.FromKilopascals(100);
    Console.WriteLine("Pressure: {0} \nTemperature: {1}", pressure.ToUnit(EngineeringUnits.Units.PressureUnit.Kilopascal), temperature.ToUnit(EngineeringUnits.Units.TemperatureUnit.DegreeCelsius));
}

Output : Pressure: 100 kPa Temperature: 293,2 K

Expected behavior: Temperature in Celsius

Observed behavior: Temperature in Kelvin

MadsKirkFoged commented 2 years ago

Thanks you very much for reporting the bug! Can you update and try again? It should be fixed now

haikal-arif commented 2 years ago

Thanks for the quick response, it's fixed now

haikal-arif commented 2 years ago

just get back to the project and found out that i overlooked the value conversion and too focused in the units

double inputVal = 300.6;
var temperature = new Temperature(inputVal, TemperatureUnit.Kelvin);
var temperatureConvert = temperature.ToUnit(TemperatureUnit.DegreeCelsius).ToString();
var temperatureCelsius = temperature.DegreesCelsius;
Console.WriteLine($"{inputVal} K is {temperatureConvert} or {temperatureCelsius:0.##} °C");

Output: 300,6 K is 0 °C or 27,45 °C

The unit is right but the value isn't consistent

MadsKirkFoged commented 2 years ago

Should be fixed now. It was a bug I made trying to fix the first bug :-D Temperature is a bit different then all other units.