/** Convert one type of unit to another type of unit @param $val value to convert @param $from unit to convert from (id) @param $to unit to convert to (id) @param $solid true if it is solid, false if not @param $system system of both to and from, 'usa' or 'metric' */ function convertTo($val, $from, $to, $solid, $system) { global $SMObj, $LangUI, $DB_LINK, $g_rb_units; // If it is a unit type that cannot be converted then just return it (unit, pinch, clove...) if (in_array($to, $g_rb_units['static']) || in_array($from, $g_rb_units['static'])) { return $val; } // If it can be converted, try... $state = NULL; if ($solid == $DB_LINK->true) { $state = "dry"; } else { $state = "wet"; } $unitFrom = Units::getUnitInfo($from, $state, $system); $unitTo = Units::getUnitInfo($to, $state, $system); if ($unitFrom == NULL || $unitTo == NULL) { // DEBUG: put this back in for warnings //echo $LangUI->_('Warning: conversion failure while trying to convert from unit ID') . " '". $from . "' " // . $LangUI->_('to unit ID') . " '". $to . "'<br />"; return -1; } else { return round($val * $unitFrom[0] / $unitTo[0] * 10000) / 10000; } }