A
download bcadd.php
Language: PHP
LOC: 19
Project Info
FreeMED Project(freemed)
Server: SourceForge
Type: cvs
...reemed\freemed\freemed\lib\
   acl.php
   API.php
   bcadd.php
   calendar-functions.php
   class.AdminModule.php
   class.Agata.php
   class.Authorizations.php
   class.BaseModule.php
   class.BillingModule.php
   class.CalendarModule.php
   class.ClaimLog.php
   class.Coverage.php
   class.Debug.php
   class.diagnosis_set.php
   class.Djvu.php
   class.EMRModule.php
   class.Fax.php
   class.FixedFormEntry.php
   ...s.FixedFormRenderer.php
   class.FormRenderer.php
   class.FreeMEDSelfTest.php
   class.GeneralConfig.php
   class.GraphModule.php
   class.Guarantor.php
   class.Handler_HL7v2.php
   ...s.Handler_HL7v2_A04.php
   ...s.Handler_HL7v2_A08.php
   ...s.Handler_HL7v2_S12.php
   ...s.Handler_HL7v2_S15.php
   class.InsuranceCompany.php
   class.LanguageRegistry.php
   class.Ledger.php
   ...s.MaintenanceModule.php
   class.Messages.php
   class.OMBS_Patient.php
   class.OMBS_Wrapper.php
   class.Parser_HL7v2.php
   class.Patient.php
   class.Payer.php
   class.PHPlot.php
   class.Physician.php
   class.Procedure.php
   class.RecordLock.php
   class.Remitt.php
   class.ReportsModule.php
   class.rxlist.php
   class.Scheduler.php
   class.TeX.php
   class.User.php
   class.UtilityModule.php
   class.vCalendar.php
   class.vCalendarEvent.php
   error_handler.php
   freemed.php
   i18n.php
   iso-set.php
   macros.php
   mail-functions.php
   settings.php
   settings.php.tmpl
   xml.php
   xmlrpc_services.php

<?php
	// $Id: bcadd.php,v 1.4 2005/04/10 12:47:20 rufustfirefly Exp $
	// $Author: rufustfirefly $

// File: bcadd
//
//	This function is meant to be a drop-in replacement for those
//	people who don't have bcmath functionality in their PHP
//	distribution. It probably has problems, and the best solution
//	is to build yourself a version with bcmath support. Barring
//	this, you can use this hack. (Jeff)
//
// 	A regex for exponential numbers is
//	[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?

// Function: bcadd
//
//	Provides bcadd functionality (from bcmath extension) without
//	having to load bcmath PHP extension.
//
// Parameters:
//
//	$left - First number to add.
//
//	$right - Second number to add.
//
//	$scale - Number of digits of precision desired after the
//	decimal point. 0 will produce an integer.
//
// Returns:
//
//	left and right added together with a precision of scale.
//
function bcadd ($left, $right, $scale) {
	// Deal with numbers smaller than $scale
	$_left = ($left < pow(10, -$scale)) ? 0 : $left;
	$_right = ($right < pow(10, -$scale)) ? 0 : $right;

	// first add the two numbers
	$sum = (double)($_left + $_right);

	// check for a dot in the number
	if (strpos($sum, ".") === false) {
		// not found, integer
		$int_part = $sum;
		$real_part = 0;
	} else {
		// if not, we split
		list ($int_part, $real_part) = explode (".", $sum);
	} // end checking for a dot

	// handle scale of 0
	if ($scale == 0) return $int_part;

	// handle real parts that need more precision
	if ($scale > strlen($real_part)) {
		for ($i=0;$i<=($scale - strlen($real_part));$i++)
			$real_part .= "0";
	} // end checking for more precision needed

	// return built string
	return $int_part . "." . substr($real_part, 0, $scale);
} // end function bcadd

?>

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us