Keine Explizite Temperatur-Umrechungs-Logik mehr im generischen JavaScript
This commit is contained in:
@@ -152,11 +152,10 @@ function createConverter(engine, config) {
|
||||
rawResult = value.times(fromFactor)
|
||||
.dividedBy(toFactor);
|
||||
} else if (engine === 'intermediate') {
|
||||
rawResult = convertTemperature(
|
||||
value,
|
||||
config.fromUnit,
|
||||
config.toUnit
|
||||
);
|
||||
let v = value.toNumber();
|
||||
v = config.toIntermediate(v);
|
||||
v = config.fromIntermediate(v);
|
||||
rawResult = new Decimal(v);
|
||||
} else {
|
||||
this.result = '';
|
||||
return;
|
||||
@@ -176,36 +175,6 @@ function createConverter(engine, config) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Temperature conversion via Celsius intermediate.
|
||||
* @param {Decimal} value
|
||||
* @param {string} fromUnit
|
||||
* @param {string} toUnit
|
||||
* @returns {number}
|
||||
*/
|
||||
function convertTemperature(value, fromUnit, toUnit) {
|
||||
let v = value.toNumber();
|
||||
if (fromUnit === 'fahrenheit') {
|
||||
v = (v - 32) * 5 / 9;
|
||||
} else if (fromUnit === 'kelvin') {
|
||||
v = v - 273.15;
|
||||
} else if (fromUnit === 'rankine') {
|
||||
v = (v - 491.67) * 5 / 9;
|
||||
} else if (fromUnit === 'reaumur') {
|
||||
v = v * 5 / 4;
|
||||
}
|
||||
if (toUnit === 'fahrenheit') {
|
||||
v = v * 9 / 5 + 32;
|
||||
} else if (toUnit === 'kelvin') {
|
||||
v = v + 273.15;
|
||||
} else if (toUnit === 'rankine') {
|
||||
v = (v + 273.15) * 9 / 5;
|
||||
} else if (toUnit === 'reaumur') {
|
||||
v = v * 4 / 5;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a number as plain digits with dot as decimal separator.
|
||||
* @param {Decimal|string|number} num
|
||||
|
||||
Reference in New Issue
Block a user