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:

2 calls to fp_truncate_decimals()
fp_render_currently_advising_box in includes/theme.inc
Draws the CurrentlyAdvisingBox which appears at the top of the screen, containing the student's information like name, major, etc.
_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 1641
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;
}