Source for file numbers.inc.php
Documentation is available at numbers.inc.php
* php functions for number handling
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* @author m2mtech <tech@m2m.at>
* @copyright 2007 m2m server software gmbh
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License Version 2
* @version $Id: numbers.inc.php 133 2007-08-24 13:59:14Z m2mtech $
* @link http://www.ea-geier.at/
* generates php native number format (dot)
* @param string/float number
* @param integer decimal precission
* @return boolean/string false / formated number
function makeDot($number, $newDecimals = false) {
if ($newDecimals) $decimals = $newDecimals;
$pattern = '/(-?\d*)[\.\,]?(\d{0,' . $decimals . '})(\d?)/';
if (!preg_match($pattern, $number, $match)) return false;
$a = (integer) $match[1];
$b = (integer) $match[2];
if (($b > 0) && ($l < $decimals)) {
for ($i = 1; $i <= $l; $i++ ) $b *= 10;
$c = (integer) $match[3];
for ($i = 1; $i < $decimals; $i++ ) $max *= 10;
while ($max > $b && $max > 1) {
* generates php native number format (dot)
* @param string/float number
* @return boolean/string false / formated number
if ($newDecimals) $decimals = $newDecimals;
$pattern = '/(-?\d*)[\.\,]?(\d*)/';
if (!preg_match($pattern, $number, $match)) return false;
$a = (integer) $match[1];
$b = (integer) $match[2];
* generates formated number
* @return boolean/array false/date array
function makeNum($number, $format = ',', $decimals = 2) {
case '.': case 'dot': default:
// don't care for decimal characters
* generates formated number without decimal limit
* @return boolean/array false/date array
return makeNum($number, $format, false);
|