- Timestamp:
- 06/09/10 13:28:56 (3 months ago)
- Files:
-
- fMoney.php (modified) (6 diffs)
- fORMMoney.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
fMoney.php
r577 r849 Hide Line Numbers 3 3 * Represents a monetary value - USD are supported by default and others can be added via ::defineCurrency() 4 4 * 5 * @copyright Copyright (c) 2008-20 09Will Bond5 * @copyright Copyright (c) 2008-2010 Will Bond 6 6 * @author Will Bond [wb] <will@flourishlib.com> 7 7 * @license http://flourishlib.com/license … … 10 10 * @link http://flourishlib.com/fMoney 11 11 * 12 * @version 1.0.0b2 12 * @version 1.0.0b3 13 * @changes 1.0.0b3 Added the `$remove_zero_fraction` parameter to ::format() [wb, 2010-06-09] 13 14 * @changes 1.0.0b2 Fixed a bug with calling ::format() when a format callback is set, fixed `NULL` `$element` handling in ::getCurrencyInfo() [wb, 2009-03-24] 14 15 * @changes 1.0.0b The initial implementation [wb, 2008-08-10] … … 142 143 * Allows setting a callback to translate or modify any return values from ::format() 143 144 * 144 * @param callback $callback The callback to pass all fNumber objects to. Should accept an fNumber object and a string currency abbreviation and return a formatted string.145 * @param callback $callback The callback to pass all fNumber objects to. Should accept an fNumber object, a string currency abbreviation and a boolean indicating if a zero-fraction should be removed - it should return a formatted string. 145 146 * @return void 146 147 */ … … 431 432 * Formats the amount by preceeding the amount with the currency symbol and adding thousands separators 432 433 * 434 * @param boolean $remove_zero_fraction If `TRUE` and all digits after the decimal place are `0`, the decimal place and all zeros are removed 433 435 * @return string The formatted (and possibly converted) value 434 436 */ 435 public function format( )437 public function format($remove_zero_fraction=FALSE) 436 438 { 437 439 if (self::$format_callback !== NULL) { 438 return call_user_func(self::$format_callback, $this->amount, $this->currency );440 return call_user_func(self::$format_callback, $this->amount, $this->currency, $remove_zero_fraction); 439 441 } 440 442 … … 462 464 $integer = join(',', $int_sections); 463 465 $fraction = (strlen($fraction)) ? '.' . $fraction : ''; 466 467 if ($remove_zero_fraction && rtrim($fraction, '.0') === '') { 468 $fraction = ''; 469 } 464 470 465 471 return $sign . $symbol . $integer . $fraction; … … 623 629 624 630 /** 625 * Copyright (c) 2008-20 09Will Bond <will@flourishlib.com>631 * Copyright (c) 2008-2010 Will Bond <will@flourishlib.com> 626 632 * 627 633 * Permission is hereby granted, free of charge, to any person obtaining a copy fORMMoney.php
r833 r849 Hide Line Numbers 11 11 * @link http://flourishlib.com/fORMMoney 12 12 * 13 * @version 1.0.0b8 13 * @version 1.0.0b9 14 * @changes 1.0.0b9 Added the `$remove_zero_fraction` parameter to prepare methods [wb, 2010-06-09] 14 15 * @changes 1.0.0b8 Changed validation messages array to use column name keys [wb, 2010-05-26] 15 16 * @changes 1.0.0b7 Fixed the `set` methods to return the record object in order to be consistent with all other `set` methods [wb, 2010-03-15] … … 342 343 $value = $values[$column]; 343 344 345 $remove_zero_fraction = FALSE; 346 if (count($parameters)) { 347 $remove_zero_fraction = $parameters[0]; 348 } 349 344 350 if ($value instanceof fMoney) { 345 $value = $value->format( );351 $value = $value->format($remove_zero_fraction); 346 352 } 347 353 … … 422 428 $signature .= " * resulting in the value including the currency symbol and thousands separators\n"; 423 429 $signature .= " * \n"; 430 $signature .= " * @param boolean \$remove_zero_fraction If a fraction of all zeros should be removed\n"; 424 431 $signature .= " * @return string The HTML-ready value\n"; 425 432 $signature .= " */\n"; 426 433 } 427 434 $prepare_method = 'prepare' . $camelized_column; 428 $signature .= 'public function ' . $prepare_method . '( )';435 $signature .= 'public function ' . $prepare_method . '($remove_zero_fraction=FALSE)'; 429 436 430 437 $signatures[$prepare_method] = $signature;
