You are here

function farm_area_format_calculated_area in farmOS 7

Format a calculated area in the default system of measurement.

Parameters

int|float $measurement: The measurement of area to format, in square meters.

bool $units: Boolean indicating whether or not to include units at the end of the string.

Return value

string Returns a formatted string.

4 calls to farm_area_format_calculated_area()
farm_area_calculate_area in modules/farm/farm_area/farm_area.module
Calculate the area of a farm area.
farm_area_calculate_area_multiple in modules/farm/farm_area/farm_area.module
Calculate the area of multiple farm areas.
farm_soil_amendment_form in modules/farm/farm_soil/farm_soil.farm_quick.amendment.inc
Soil amendment quick form.
farm_soil_disturbance_form in modules/farm/farm_soil/farm_soil.farm_quick.disturbance.inc
Soil disturbance quick form.

File

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

Code

function farm_area_format_calculated_area($measurement, $units = TRUE) {

  // If the measurement is empty or not a number, return an empty string.
  if (empty($measurement) || !is_numeric($measurement)) {
    return '0';
  }

  // Determine the relative size of the area.
  $size = farm_area_relative_size($measurement);

  // Get the default units for the relative size.
  $unit = farm_area_default_units('area', $size);

  // Convert the measurement to default units.
  $converted = farm_area_convert_area_units($measurement, $unit);

  // Round to 2 decimal precision.
  $output = (string) round($converted, 2);

  // Return (optionally with units).
  if (!empty($units)) {
    return $output . ' ' . $unit;
  }
  return $output;
}