diff --git a/includes/common.php b/includes/common.php index 81aea0d903..bbd921e867 100644 --- a/includes/common.php +++ b/includes/common.php @@ -735,6 +735,23 @@ function celsius_to_fahrenheit($value, $scale = 'celsius') return sprintf('%.02f', $value); } +/** + * Converts kelvin to fahrenheit (with 2 decimal places) + * if $scale is not celsius, it assumes celsius and returns the value + * + * @param float $value + * @param string $scale fahrenheit or celsius + * @return string (containing a float) + */ +function kelvin_to_celsius($value, $scale = 'celsius') +{ + if ($scale === 'celsius') { + $value = $value - 273.15; + } + + return sprintf('%.02f', $value); +} + /** * Converts string to float */ diff --git a/includes/html/modal/new_customoid.inc.php b/includes/html/modal/new_customoid.inc.php index 327e9a3716..2a9bfddea1 100644 --- a/includes/html/modal/new_customoid.inc.php +++ b/includes/html/modal/new_customoid.inc.php @@ -67,6 +67,7 @@ if (! (Auth::user()->hasGlobalAdmin())) { + diff --git a/includes/polling/customoid.inc.php b/includes/polling/customoid.inc.php index e49538271b..84414dc76c 100644 --- a/includes/polling/customoid.inc.php +++ b/includes/polling/customoid.inc.php @@ -15,6 +15,7 @@ foreach (dbFetchRows('SELECT * FROM `customoids` WHERE `customoid_passed` = 1 AN $user_funcs = [ 'celsius_to_fahrenheit', 'fahrenheit_to_celsius', + 'kelvin_to_celsius', 'uw_to_dbm', ];