Introducción a Zend Framework

 Aprendiendo Zend Framework

Apéndice

 Referencia de Zend Framework


  • Zend_Gdata
  • Zend_Http
  • Zend_InfoCard
  • Zend_Json
  • Zend_Layout
  • Zend_Ldap
  • Zend_Loader
  • Zend_Locale
  • Zend_Log
  • Zend_Mail
  • Zend_Markup
  • Zend_Measure
  • Zend_Memory
  • Zend_Mime
  • Zend_Navigation
  • Zend_Oauth
  • Zend_OpenId
  • Zend_Paginator
  • Zend_Pdf
  • Zend_ProgressBar
  • Zend_Queue
  • Zend_Reflection
  • Zend_Registry
  • Zend_Rest

  • Zend_Search_Lucene
  • Zend_Serializer
  • Zend_Server
  • Zend_Service
  • Zend_Session
  • Zend_Soap
  • Zend_Tag
  • Zend_Test
  • Zend_Text
  • Zend_TimeSync
  • Zend_Tool
  • Zend_Tool_Framework
  • Zend_Tool_Project
  • Zend_Translate
  • Zend_Uri
  • Zend_Validate
  • Zend_Version
  • Zend_View
  • Zend_Wildfire
  • Zend_XmlRpc
  • ZendX_Console_Process_Unix
  • ZendX_JQuery
  • Traducción al 26.9% - Actualizado el 2011-11-16 - Revisión 24249 - Versión ZF 1.11.x

    25.8. Calculating with currencies

    When working with currencies you will sometimes also have to calculate with them. Zend_Currency allows you to do this with some simple methods. The following methods are supported for calculation:

    • add(): This method adds the given currency to the existing currency object.

    • sub(): This method substracts the given currency from the existing currency object.

    • div(): This method divides the given currency from the existing currency object.

    • mul(): This method multiplies the given currency with the existing currency object.

    • mod(): This method calculates the remaining value (modulo) from dividing the given currency from the existing currency object.

    • compare(): This method compares the given currency with the existing currency object. When both values are equal it returns '0'. When the existing currency value is greater than the given, this method will return 1. Otherwise you will get '-1' returned.

    • equals(): This method compares the given currency with the existing currency object. When both values are equal it returns TRUE, otherwise FALSE.

    • isMore(): This method compares the given currency with the existing currency object. When the existing currency is greater than the given one, you will get TRUE in return, otherwise FALSE.

    • isLess(): This method compares the given currency with the existing currency object. When the existing currency is less than the given one, you will get TRUE in return, otherwise FALSE.

    As you can see the multiple methods allow any kind of calculation with Zend_Currency. See the next snippets as example:

    $currency = new Zend_Currency(
        array(
            
    'value'    => 1000,
            
    'currency' => 'USD',
        )
    );

    print 
    $currency// Could return '$ 1.000,00'

    $currency->add(500);
    print 
    $currency// Could return '$ 1.500,00'
    $currency_2 = new Zend_Currency(
        array(
            
    'value'    => 500,
            
    'currency' => 'USD',
        )
    );

    if (
    $currency->isMore($currency_2)) {
        print 
    "First is more";
    }

    $currency->div(5);
    print 
    $currency// Could return '$ 200,00'
    digg delicious meneame google twitter technorati facebook

    Comentarios

    Loading...