function fp_truncate_decimals

7.x misc.inc fp_truncate_decimals($num, $places = 2)
6.x misc.inc fp_truncate_decimals($num, $places = 2)
5.x misc.inc fp_truncate_decimals($num, $places = 2)

This simple function will take a number and truncate the number of decimals to the requested places. This can be used in place of number_format(), which *rounds* numbers.

For example, number_format(1.99999, 2) gives you 2.00. But THIS function gives: fp_truncate_decimals(1.999999, 2) = 1.99

Parameters

unknown_type $places:

10 calls to fp_truncate_decimals()
AdvisingScreen.php in classes/AdvisingScreen.php
AdvisingScreen::draw_progress_boxes in classes/AdvisingScreen.php
This function calls drawPieChart to construct the student's 3 progress pie charts.
audit.module in modules/audit/audit.module
This is the Audit module, which provides functionality relating to degree audits.
audit_display_audit in modules/audit/audit.module
fp_render_student_profile_header in includes/theme.inc
Returns the HTML for the "profile" header html for a student

... See full list

File

includes/misc.inc, line 3005
This file contains misc functions for FlightPath

Code

function fp_truncate_decimals($num, $places = 2) {

  // does $num contain a .?  If not, add it on.
  if (!strstr("" . $num, ".")) {
    $num .= ".0";
  }

  // Break it by .
  $temp = explode(".", "" . $num);

  // Get just the decimals and trim 'em
  $decimals = trim(substr($temp [1], 0, $places));
  if (strlen($decimals) < $places) {
    // Padd with zeros on the right!
    $decimals = str_pad($decimals, $places, "0", STR_PAD_RIGHT);
  }

  $new_num = $temp [0] . "." . $decimals;

  return $new_num;
}