当前位置: 首页>>代码示例>>PHP>>正文


PHP Math::round方法代码示例

本文整理汇总了PHP中Math::round方法的典型用法代码示例。如果您正苦于以下问题:PHP Math::round方法的具体用法?PHP Math::round怎么用?PHP Math::round使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Math的用法示例。


在下文中一共展示了Math::round方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: toNumber

    /**
     * Returns a locale formatted number depending on the given options.
     * The seperation and fraction sign is used from the set locale.
     * ##0.#  -> 12345.12345 -> 12345.12345
     * ##0.00 -> 12345.12345 -> 12345.12
     * ##,##0.00 -> 12345.12345 -> 12,345.12
     *
     * @param   string  $input    Localized number string
     * @param   array   $options  Options: number_format, locale, precision. See {@link setOptions()} for details.
     * @throws \Zend\Locale\Exception\InvalidArgumentException
     * @return  string  locale formatted number
     */
    public static function toNumber($value, array $options = array())
    {
        $value             = Math::normalize($value);
        $value             = Math::floatalize($value);
        $options           = self::_checkOptions($options) + self::$_options;
        $options['locale'] = (string) $options['locale'];

        // Get correct signs for this locale
        $symbols = Cldr::getList($options['locale'], 'symbols');
        $oenc = iconv_get_encoding('internal_encoding');
        iconv_set_encoding('internal_encoding', 'UTF-8');

        // Get format
        $format = $options['number_format'];
        if ($format === null) {
            $format  = Cldr::getContent($options['locale'], 'decimalnumber');
            $format  = self::_seperateFormat($format, $value, $options['precision']);

            if ($options['precision'] !== null) {
                $value   = Math::normalize(Math::round($value, $options['precision']));
            }
        } else {
            // seperate negative format pattern when available
            $format  = self::_seperateFormat($format, $value, $options['precision']);
            if (strpos($format, '.')) {
                if (is_numeric($options['precision'])) {
                    $value = Math::round($value, $options['precision']);
                } else {
                    if (substr($format, iconv_strpos($format, '.') + 1, 3) == '###') {
                        $options['precision'] = null;
                    } else {
                        $options['precision'] = iconv_strlen(iconv_substr($format, iconv_strpos($format, '.') + 1,
                                                             iconv_strrpos($format, '0') - iconv_strpos($format, '.')));
                        $format = iconv_substr($format, 0, iconv_strpos($format, '.') + 1) . '###'
                                . iconv_substr($format, iconv_strrpos($format, '0') + 1);
                    }
                }
            } else {
                $value = Math::round($value, 0);
                $options['precision'] = 0;
            }
            $value = Math::normalize($value);
        }

        if (iconv_strpos($format, '0') === false) {
            iconv_set_encoding('internal_encoding', $oenc);
            throw new Exception\InvalidArgumentException(
              'Wrong format... missing 0'
            );
        }

        // get number parts
        $pos = iconv_strpos($value, '.');
        if ($pos !== false) {
            if ($options['precision'] === null) {
                $precstr = iconv_substr($value, $pos + 1);
            } else {
                $precstr = iconv_substr($value, $pos + 1, $options['precision']);
                if (iconv_strlen($precstr) < $options['precision']) {
                    $precstr = $precstr . str_pad("0", ($options['precision'] - iconv_strlen($precstr)), "0");
                }
            }
        } else {
            if ($options['precision'] > 0) {
                $precstr = str_pad("0", ($options['precision']), "0");
            }
        }

        if ($options['precision'] === null) {
            if (isset($precstr)) {
                $options['precision'] = iconv_strlen($precstr);
            } else {
                $options['precision'] = 0;
            }
        }

        // get fraction and format lengths
        if (strpos($value, '.') !== false) {
            $number = substr((string) $value, 0, strpos($value, '.'));
        } else {
            $number = $value;
        }

        $prec = call_user_func(Math::$sub, $value, $number, $options['precision']);
        $prec = Math::floatalize($prec);
        $prec = Math::normalize($prec);
        if (iconv_strpos($prec, '-') !== false) {
            $prec = iconv_substr($prec, 1);
//.........这里部分代码省略.........
开发者ID:rkeplin,项目名称:zf2,代码行数:101,代码来源:Format.php

示例2: getMetricsFromBytes

 public function getMetricsFromBytes($bs, &$output)
 {
     $output = $output;
     $width = 0;
     $height = 0;
     $dpi = 0;
     $baseline = 0;
     $bys = haxe_io_Bytes::ofData($bs);
     $bi = new haxe_io_BytesInput($bys, null, null);
     $n = $bys->length;
     $alloc = 10;
     $b = haxe_io_Bytes::alloc($alloc);
     $bi->readBytes($b, 0, 8);
     $n -= 8;
     while ($n > 0) {
         $len = com_wiris_system_InputEx::readInt32_($bi);
         $typ = com_wiris_system_InputEx::readInt32_($bi);
         if ($typ === 1229472850) {
             $width = com_wiris_system_InputEx::readInt32_($bi);
             $height = com_wiris_system_InputEx::readInt32_($bi);
             com_wiris_system_InputEx::readInt32_($bi);
             $bi->readByte();
         } else {
             if ($typ === 1650545477) {
                 $baseline = com_wiris_system_InputEx::readInt32_($bi);
             } else {
                 if ($typ === 1883789683) {
                     $dpi = com_wiris_system_InputEx::readInt32_($bi);
                     $dpi = Math::round($dpi / 39.37);
                     com_wiris_system_InputEx::readInt32_($bi);
                     $bi->readByte();
                 } else {
                     if ($len > $alloc) {
                         $alloc = $len;
                         $b = haxe_io_Bytes::alloc($alloc);
                     }
                     $bi->readBytes($b, 0, $len);
                 }
             }
         }
         com_wiris_system_InputEx::readInt32_($bi);
         $n -= $len + 12;
         unset($typ, $len);
     }
     $r = null;
     if ($output !== null) {
         $output["width"] = "" . _hx_string_rec($width, "");
         $output["height"] = "" . _hx_string_rec($height, "");
         $output["baseline"] = "" . _hx_string_rec($baseline, "");
         if ($dpi !== 96) {
             $output["dpi"] = "" . _hx_string_rec($dpi, "");
         }
         $r = "";
     } else {
         $r = "&cw=" . _hx_string_rec($width, "") . "&ch=" . _hx_string_rec($height, "") . "&cb=" . _hx_string_rec($baseline, "");
         if ($dpi !== 96) {
             $r = $r . "&dpi=" . _hx_string_rec($dpi, "");
         }
     }
     return $r;
 }
开发者ID:Raniratna,项目名称:new_elearning,代码行数:61,代码来源:RenderImpl.class.php

示例3: getInt

 static function getInt($n)
 {
     if (Std::is($n, _hx_qtype("Float"))) {
         return Math::round($n);
     } else {
         if (Std::is($n, _hx_qtype("Int"))) {
             return $n;
         } else {
             return 0;
         }
     }
 }
开发者ID:komcdo,项目名称:winnow,代码行数:12,代码来源:JSon.class.php

示例4: alignCore2


//.........这里部分代码省略.........
                         $mem->set($key, 1);
                         $ct++;
                     }
                     unset($key, $j1);
                 }
                 unset($_g21);
                 $_g22 = 0;
                 while ($_g22 < $hb) {
                     $j2 = $_g22++;
                     $key1 = $av->toString($b->getCell($cb, $j2));
                     if (!$mem2->exists($key1)) {
                         $mem2->set($key1, 1);
                         $ct++;
                     }
                     unset($key1, $j2);
                 }
                 unset($_g22);
                 $columns_eval->push(new _hx_array(array($i, $ct)));
                 unset($mem2, $mem, $i, $ct, $cb, $ca);
             }
             $sorter = array(new _hx_lambda(array(&$N, &$a, &$align, &$av, &$b, &$column_order, &$columns, &$columns_eval, &$common_units, &$ha, &$hb, &$ids, &$ignore, &$index_top, &$pending_ct, &$ra_header, &$rb_header, &$reverse_pending_ct, &$used, &$used_reverse, &$w), "coopy_CompareTable_0"), 'execute');
             $columns_eval->sort($sorter);
             $columns = Lambda::harray(Lambda::map($columns_eval, array(new _hx_lambda(array(&$N, &$a, &$align, &$av, &$b, &$column_order, &$columns, &$columns_eval, &$common_units, &$ha, &$hb, &$ids, &$ignore, &$index_top, &$pending_ct, &$ra_header, &$rb_header, &$reverse_pending_ct, &$sorter, &$used, &$used_reverse, &$w), "coopy_CompareTable_1"), 'execute')));
             $columns = $columns->slice(0, $N);
         } else {
             $_g12 = 0;
             $_g6 = $common_units->length;
             while ($_g12 < $_g6) {
                 $i1 = $_g12++;
                 $columns->push($i1);
                 unset($i1);
             }
         }
         $top = Math::round(Math::pow(2, $columns->length));
         $pending = new haxe_ds_IntMap();
         $_g7 = 0;
         while ($_g7 < $ha) {
             $j3 = $_g7++;
             $pending->set($j3, $j3);
             unset($j3);
         }
         $added_columns = new haxe_ds_IntMap();
         $index_ct = 0;
         $_g8 = 0;
         while ($_g8 < $top) {
             $k = $_g8++;
             if ($k === 0) {
                 continue;
             }
             if ($pending_ct === 0) {
                 break;
             }
             $active_columns = new _hx_array(array());
             $kk = $k;
             $at = 0;
             while ($kk > 0) {
                 if (_hx_mod($kk, 2) === 1) {
                     $active_columns->push($columns[$at]);
                 }
                 $kk >>= 1;
                 $at++;
             }
             $index = new coopy_IndexPair($this->comp->compare_flags);
             $_g23 = 0;
             $_g13 = $active_columns->length;
             while ($_g23 < $_g13) {
开发者ID:sp-ruben-simon,项目名称:daff-php,代码行数:67,代码来源:CompareTable.class.php

示例5: getTimes

 static function getTimes($date, $lat, $lng)
 {
     $lw = suncalc_SunCalc::$rad * -$lng;
     $phi = suncalc_SunCalc::$rad * $lat;
     $d = suncalc_SunCalc::toDays($date);
     $n = Math::round($d - suncalc_SunCalc::$J0 - $lw / (2 * Math::$PI));
     $ds = suncalc_SunCalc::approxTransit(0, $lw, $n);
     $M = suncalc_SunCalc::solarMeanAnomaly($ds);
     $L = suncalc_SunCalc::eclipticLongitude($M);
     $dec = suncalc_SunCalc::declination($L, 0);
     $Jnoon = suncalc_SunCalc::solarTransitJ($ds, $M, $L);
     $i = null;
     $len = null;
     $time = null;
     $Jset = null;
     $Jrise = null;
     $result = new haxe_ds_StringMap();
     $v = suncalc_SunCalc::fromJulian($Jnoon);
     $result->set("solarNoon", $v);
     $v;
     $v1 = suncalc_SunCalc::fromJulian($Jnoon - 0.5);
     $result->set("nadir", $v1);
     $v1;
     $_g = 0;
     $_g1 = suncalc_SunCalc::$times;
     while ($_g < $_g1->length) {
         $time1 = $_g1[$_g];
         ++$_g;
         $Jset = suncalc_SunCalc::getSetJ($time1->a[0] * suncalc_SunCalc::$rad, $lw, $phi, $dec, $n, $M, $L);
         $Jrise = $Jnoon - ($Jset - $Jnoon);
         $k = $time1[1];
         $v2 = suncalc_SunCalc::fromJulian($Jrise);
         $result->set($k, $v2);
         $v2;
         unset($v2, $k);
         $k1 = $time1[2];
         $v3 = suncalc_SunCalc::fromJulian($Jset);
         $result->set($k1, $v3);
         $v3;
         unset($v3, $k1);
         unset($time1);
     }
     return $result;
 }
开发者ID:ypid,项目名称:suncalc-php,代码行数:44,代码来源:SunCalc.class.php

示例6: percentf

 public function percentf($t_stop = null)
 {
     return Std::string(Math::round($this->percent($t_stop))) . "%";
 }
开发者ID:marcdraco,项目名称:Webrathea,代码行数:4,代码来源:Pcall.class.php

示例7: format_profiler_message

 static function format_profiler_message($type, $instance)
 {
     $t = new StringBuf();
     if ($instance->calls > 0) {
         $t->add("<td>" . _hx_string_or_null($type) . "</td>");
         $t->add("<td>" . Std::string($instance->calls) . "</td>");
         $t->add("<td>" . _hx_string_or_null(system_base_Database::sprint_float($instance->time, 6)) . "</td>");
         $t->add("<td class=\"__hand__\" title = '" . Std::string($instance->fast_sql) . "'>" . _hx_string_or_null(system_base_Database::sprint_float($instance->fast, 6)) . "</td>");
         $t->add("<td class=\"__hand__\" title = '" . Std::string($instance->slow_sql) . "'>" . _hx_string_or_null(system_base_Database::sprint_float($instance->slow, 6)) . "</td>");
         $t->add("<td>" . Std::string($instance->percentf(null)) . "</td>");
         $t->add("<td>" . Std::string(Math::round($instance->percent(null) / $instance->calls)) . "%</td>");
         return $t->b;
     } else {
         $t->add("<td>" . _hx_string_or_null($type) . "</td>");
         $t->add("<td></td>");
         $t->add("<td></td>");
         $t->add("<td></td>");
         $t->add("<td></td>");
         $t->add("<td></td>");
         $t->add("<td></td>");
         return $t->b;
     }
 }
开发者ID:marcdraco,项目名称:Webrathea,代码行数:23,代码来源:Cache.class.php


注:本文中的Math::round方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。