Source for file form_field_money.class.php
Documentation is available at form_field_money.class.php
// *** Tangra (Application Framework and Tools for PHP)
* Contains class Form_Field_Date
require_once(TANGRA_MAIN_DIR. 'form/fields/text/form_field_text.class.php');
* Represents text field that accepts money value
* Please note that currency sign is not accepted
* Separator for thousands
* Enter description here...
* @param string $name Name of the field
* @param boolean $required Is field required. Default is false
* @param integer $maxlength Maximum length of the text. Default is 100
* @param string $value Default value
* @param string $thousands_separator Thousands separator
* @param string $floating_separator Decimal separator
function __construct($name, $required = false, $maxlength = 100, $value = NULL, $thousands_separator = ' ', $floating_separator = '.') {
parent::__construct($name, $required, $maxlength, $value);
* @param string $thousands_separator Thousands separator
* @param string $floating_separator Decimal separator
public function set_separators($thousands_separator, $floating_separator) {
if ($thousands_separator == $floating_separator) {
throw new Tangra_Exception('Thousands separator and Floating separator can not be the same = '. $thousands_separator);
if ($thousands_separator != ',' && $thousands_separator != ' ' && $thousands_separator != '.' && $thousands_separator != '') {
throw new Tangra_Exception('Invalid thousands separator = "'. $thousands_separator. '". Must be "," (comma) or " "(space) or empty.');
if ($floating_separator != '.' && $floating_separator != ",") {
throw new Tangra_Exception('Invalid floating separator = "'. $floating_separator. '". Must be "."(dot) or ","(comma)');
* Returns thousands separator
* Returns decimal separator
* Alias of get_floating_separator
* Performs basic check for validity
* Transfers data from html_value to value
* Converts money value to integer
//TODO - make it to accept value without leading 0, e.g. ".45"
//removing thousends separator
$fsp = strpos($value, $floating_separator);
// ensuring that floating separator is present only one time
if (!strpos($value, $floating_separator, $fsp + 1)) {
$base = substr($value, 0, $fsp);
$fraction = substr($value, $fsp + 1);
$ret = $base. $fraction. '0';
|