You are here

function farm_area_convert_area_units in farmOS 7

Convert an area from square meters to another unit.

Parameters

$input: The number to convert (assumed to be in square meters).

string $unit: Specify the units to convert to. Must be one of: hectares, acres, or square feet.

Return value

string Returns the converted number as string.

2 calls to farm_area_convert_area_units()
farm_area_format_calculated_area in modules/farm/farm_area/farm_area.module
Format a calculated area in the default system of measurement.
farm_area_relative_size in modules/farm/farm_area/farm_area.module
Subjectively define the relative size of an area measurement.

File

modules/farm/farm_area/farm_area.module, line 510

Code

function farm_area_convert_area_units($input, $unit) {

  // Define the available conversion units and their coefficients.
  $conversion = array(
    'square meters' => '1',
    'hectares' => '0.0001',
    'square feet' => '10.7639',
    'acres' => '0.000247105',
  );

  // If the unit is not in the list, do nothing.
  if (!array_key_exists($unit, $conversion)) {
    return $input;
  }

  // Set BCMath scale.
  farm_map_set_bcscale();

  // Convert to the desired units.
  if (function_exists('bcmul')) {
    $output = bcmul($input, $conversion[$unit]);
  }
  else {
    $output = floatval($input) * $conversion[$unit];
  }

  // Reset BCMath scale.
  farm_map_reset_bcscale();

  // Return the result.
  return $output;
}