/**
  * Test the number formatting method
  *
  */
 function test_formatNumber()
 {
     $dec_point_save = $GLOBALS['phpAds_DecimalPoint'];
     $thousands_save = $GLOBALS['phpAds_ThousandsSeperator'];
     $decimals_save = $GLOBALS['_MAX']['PREF']['ui_percentage_decimals'];
     $GLOBALS['phpAds_DecimalPoint'] = '.';
     $GLOBALS['phpAds_ThousandsSeperator'] = ',';
     $GLOBALS['_MAX']['PREF']['ui_percentage_decimals'] = 2;
     $number = 3.141592653589793 * 1000;
     $this->assertEqual('1,234', OA_Admin_NumberFormat::formatNumber("1234", 0));
     $this->assertEqual('3,141.59', OA_Admin_NumberFormat::formatNumber($number));
     $this->assertEqual('3,141.593', OA_Admin_NumberFormat::formatNumber($number, 3));
     $this->assertEqual('3,141,5927', OA_Admin_NumberFormat::formatNumber($number, 4, ','));
     $this->assertEqual('3.141,59265', OA_Admin_NumberFormat::formatNumber($number, 5, ',', '.'));
     // Change defaults
     $GLOBALS['phpAds_DecimalPoint'] = ',';
     $GLOBALS['phpAds_ThousandsSeperator'] = '.';
     $GLOBALS['_MAX']['PREF']['ui_percentage_decimals'] = 4;
     $this->assertEqual('3.141,5927', OA_Admin_NumberFormat::formatNumber($number));
     $this->assertEqual('3.141,593', OA_Admin_NumberFormat::formatNumber($number, 3));
     $this->assertEqual('3.141,5927', OA_Admin_NumberFormat::formatNumber($number, 4, ','));
     $this->assertEqual('3.141,59265', OA_Admin_NumberFormat::formatNumber($number, 5, ',', '.'));
     // Test NAN (NotANumber)
     $this->assertFalse(OA_Admin_NumberFormat::formatNumber('string'));
     // Clean up
     $GLOBALS['phpAds_DecimalPoint'] = $dec_point_save;
     $GLOBALS['phpAds_ThousandsSeperator'] = $thousands_save;
     $GLOBALS['_MAX']['PREF']['ui_percentage_decimals'] = $decimals_save;
 }
function smarty_modifier_formatNumber($number)
{
    return OA_Admin_NumberFormat::formatNumber($number, 0);
}
/**
 *
 * Correction revenue from other formats (23234,34 or 23 234,34 or 23.234,34)
 * to format acceptable by is_numeric (23234.34)
 *
 * @param array $aFields  Array of exported form fields
 * @param array $errors  Array of pear errors
 * @param String $field  Numeric field which will be checked and converted
 * @param String $errrorString     Error string used in case format of the field is not correct
 */
function correctAdnCheckNumericFormField($aFields, $errors, $field, $errrorString)
{
    $corrected = OA_Admin_NumberFormat::unformatNumber($aFields[$field]);
    if ($corrected !== false) {
        $aFields[$field] = $corrected;
    }
    if (!empty($aFields[$field]) && !is_numeric($aFields[$field])) {
        // Suppress PEAR error handling to show this error only on top of HTML form
        PEAR::pushErrorHandling(null);
        $errors[] = PEAR::raiseError($GLOBALS[$errrorString]);
        PEAR::popErrorHandling();
    }
}