Wprowadzenie do Zend Framework

     Nauka Zend Framework


     Przewodnik po 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
  • Translation 21.3% Update 2011-11-16 - Revision 24356 - Version ZF 1.11.x

    45.2. Creation of Measurements

    When creating a measurement object, Zend_Measure_* methods expect the input/original measurement data value as the first parameter. This can be a numeric argument, a String without units, or a localized string with unit(s) specified. The second parameter defines the type of the measurement. Both parameters are mandatory. The language may optionally be specified as the third parameter.

    45.2.1. Creating measurements from integers and floats

    In addition to integer data values, floating point types may be used, but "simple decimal fractions like 0.1 or 0.7 cannot be converted into their internal binary counterparts without a little loss of precision," sometimes giving surprising results. Also, do not compare two "float" type numbers for equality.

    Przykład 45.3. Creation using integer and floating values

    $measurement 1234.7;
    $unit = new Zend_Measure_Length((integer)$measurement,
    // outputs '1234 m' (meters)

    $unit = new Zend_Measure_Length($measurementZend_Measure_Length::STANDARD);
    // outputs '1234.7 m' (meters)

    45.2.2. Creating measurements from strings

    Many measurements received as input to Zend Framework applications can only be passed to Zend_Measure_* classes as strings, such as numbers written using roman numerals or extremely large binary values that exceed the precision of PHP's native integer and float types. Since integers can be denoted using strings, if there is any risk of losing precision due to limitations of PHP's native integer and float types, using strings instead. Zend_Measure_Number uses the BCMath extension to support arbitrary precision, as shown in the example below, to avoid limitations in many PHP functions, such as bin2dec().

    Przykład 45.4. Creation using strings

    $mystring "10010100111010111010100001011011101010001";
    $unit = new Zend_Measure_Number($mystringZend_Measure_Number::BINARY);


    45.2.3. Measurements from localized strings

    When a string is entered in a localized notation, the correct interpretation can not be determined without knowing the intended locale. The division of decimal digits with "." and grouping of thousands with "," is common in the English language, but not so in other languages. For example, the English number "1,234.50" would be interpreted as meaning "1.2345" in German. To deal with such problems, the locale-aware Zend_Measure_* family of classes offer the possibility to specify a language or region to disambiguate the input data and properly interpret the intended semantic value.

    Przykład 45.5. Localized string

    $locale = new Zend_Locale('de');
    $mystring "1,234.50";
    $unit = new Zend_Measure_Length($mystring,
    $unit// outputs "1.234 m"

    $mystring "1,234.50";
    $unit = new Zend_Measure_Length($mystring,
    $unit// outputs "1234.50 m"

    Since Zend Framework 1.7.0 Zend_Measure does also support the usage of an application wide locale. You can simply set a Zend_Locale instance to the registry like shown below. With this notation you can forget about setting the locale manually with each instance when you want to use the same locale multiple times.

    // in your bootstrap file
    $locale = new Zend_Locale('de_AT');

    // somewhere in your application
    $length = new Zend_Measure_Length(Zend_Measure_Length::METER();
    digg delicious meneame google twitter technorati facebook