function fp_truncate_decimals

6.x misc.inc fp_truncate_decimals($num, $places = 2)
4.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:

5 calls to fp_truncate_decimals()
AdvisingScreen::draw_progress_boxes in classes/AdvisingScreen.php
This function calls drawPieChart to construct the student's 3 progress pie charts.
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
stats_report_major_students_progress_perform_batch_operation in modules/stats/reports.major-students-progress.inc
This is the actual batch process function which gets called per run of the batch.
Student::calculate_cumulative_hours_and_gpa in classes/Student.php
This function will look at the courses which the student has taken, to calculate the cumulative hours and gpa, rather than just load them from the db table.

File

includes/misc.inc, line 2934
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;
}