I am trying to write some logic to convert Celsius to Fahrenheit and when passed a negative value, it returns NaN
. Not sure why. Here is my Fahrenheit offset:
const fahrenheitOffset = (value) => (value * 1.8) + 32;
and here is my function:
function celsiusToFarenheit(celsiusValue) {
return parseFloat((fahrenheitOffset(celsiusValue)).toFixed(2));
}
and another function to convert it to a string:
function celsiusToFarenheitString(value) {
return `${parseFloat(fahrenheitOffset(value)).toFixed(1)}°F`;
}
when I run these tests, I get NaN
rather than '-0.55'
test('returns Farenheit float if Farenheit output is requested and valid reading passed', () => {
expect(temperatureConverter(
'-0.55',
unitTypesEnums.FAHRENHEIT.string,
converterReturnTypeEnums.FLOAT)
).toEqual(celsiusToFarenheit(parsed));
});
test('returns Fahrenheit string if Fahrenheit output is requested and valid reading passed in', () => {
expect(temperatureConverter(
'-0.55',
unitTypesEnums.FAHRENHEIT.string,
converterReturnTypeEnums.STRING)
).toEqual(celsiusToFarenheitString(parsed));
});