本文整理汇总了PHP中Num::round方法的典型用法代码示例。如果您正苦于以下问题:PHP Num::round方法的具体用法?PHP Num::round怎么用?PHP Num::round使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Num
的用法示例。
在下文中一共展示了Num::round方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_round
/**
* @test
* @dataProvider provider_round
* @param number $input
* @param integer $precision
* @param integer $mode
* @param number $expected
*/
function test_round($input, $precision, $expected)
{
foreach (array(Num::ROUND_HALF_UP, Num::ROUND_HALF_DOWN, Num::ROUND_HALF_EVEN, Num::ROUND_HALF_ODD) as $i => $mode) {
$this->assertSame($expected[$i], Num::round($input, $precision, $mode, false));
}
}
示例2: tickets_closed_by_date
/**
* Returns array with Tickets Closed by date formatted to generate charts
* @param timestamp $from_date
* @param timestamp $to_date
* @return array
*/
private function tickets_closed_by_date($from_date, $to_date)
{
// Dates range we are filtering
$dates = $this->dates_range($from_date, $to_date);
$query = DB::select(DB::expr('DATE(read_date) date'))->select(DB::expr('COUNT(id_ticket) total'))->from('tickets')->where('read_date', '!=', 'NULL')->where('status', '=', Model_Ticket::STATUS_CLOSED)->where('read_date', 'between', array(Date::unix2mysql($from_date), Date::unix2mysql($to_date)));
$query = $query->group_by(DB::expr('DATE(read_date)'))->order_by('date', 'asc')->execute();
$result = $query->as_array('date');
$ret = array();
// print maxinum 30 date labels on charts
$label_counter = 0;
$label_breaker = count($dates) > 30 ? Num::round(count($dates) / 30) : 1;
foreach ($dates as $k => $date) {
$count_sum = isset($result[$date['date']]['total']) ? $result[$date['date']]['total'] : 0;
$ret[] = array('date' => $label_counter % $label_breaker == 0 ? $date['date'] : '', '#' => $count_sum);
$label_counter++;
}
return $ret;
}
示例3: action_advanced_search
public function action_advanced_search()
{
if (Theme::get('infinite_scroll')) {
$this->template->scripts['footer'][] = '//cdn.jsdelivr.net/jquery.infinitescroll/2.0b2/jquery.infinitescroll.js';
$this->template->scripts['footer'][] = 'js/listing.js';
}
if (core::config('general.auto_locate') or core::config('advertisement.map')) {
Theme::$scripts['async_defer'][] = '//maps.google.com/maps/api/js?libraries=geometry,places&v=3&key=' . core::config("advertisement.gm_api_key") . '&callback=initLocationsGMap';
}
$this->template->scripts['footer'][] = 'js/jquery.toolbar.js';
$this->template->scripts['footer'][] = 'js/sort.js';
//template header
$this->template->title = __('Advanced Search');
$this->template->meta_description = __('Search in') . ' ' . core::config('general.site_name');
//breadcrumbs
Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default')));
Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title));
$pagination = NULL;
$ads = NULL;
$res_count = NULL;
$user = $this->user ? $this->user : NULL;
if ($this->request->query()) {
// variables
$search_advert = core::get('title');
$search_loc = core::get('location');
// filter by each variable
$ads = new Model_Ad();
//if sort by distance
if ((core::request('sort', core::config('advertisement.sort_by')) == 'distance' or core::request('userpos') == 1) and Model_User::get_userlatlng()) {
$ads->select(array(DB::expr('degrees(acos(sin(radians(' . $_COOKIE['mylat'] . ')) * sin(radians(`latitude`)) + cos(radians(' . $_COOKIE['mylat'] . ')) * cos(radians(`latitude`)) * cos(radians(abs(' . $_COOKIE['mylng'] . ' - `longitude`))))) * 111.321'), 'distance'))->where('latitude', 'IS NOT', NULL)->where('longitude', 'IS NOT', NULL);
}
// early filter
$ads = $ads->where('status', '=', Model_Ad::STATUS_PUBLISHED);
//if ad have passed expiration time dont show
if (core::config('advertisement.expire_date') > 0) {
$ads->where(DB::expr('DATE_ADD( published, INTERVAL ' . core::config('advertisement.expire_date') . ' DAY)'), '>', Date::unix2mysql());
}
if (core::request('userpos') == 1 and Model_User::get_userlatlng()) {
if (is_numeric(Core::cookie('mydistance')) and Core::cookie('mydistance') <= 500) {
$location_distance = Core::config('general.measurement') == 'imperial' ? Num::round(Core::cookie('mydistance') * 1.60934) : Core::cookie('mydistance');
} else {
$location_distance = Core::config('general.measurement') == 'imperial' ? Num::round(Core::config('advertisement.auto_locate_distance') * 1.60934) : Core::config('advertisement.auto_locate_distance');
}
$ads->where(DB::expr('degrees(acos(sin(radians(' . $_COOKIE['mylat'] . ')) * sin(radians(`latitude`)) + cos(radians(' . $_COOKIE['mylat'] . ')) * cos(radians(`latitude`)) * cos(radians(abs(' . $_COOKIE['mylng'] . ' - `longitude`))))) * 111.321'), '<=', $location_distance);
}
if (!empty($search_advert) or core::get('search') !== NULL and strlen(core::get('search')) >= 3) {
// if user is using search from header
if (core::get('search')) {
$search_advert = core::get('search');
}
if (core::config('general.search_by_description') == TRUE) {
$ads->where_open()->where('title', 'like', '%' . $search_advert . '%')->or_where('description', 'like', '%' . $search_advert . '%')->where_close();
} else {
$ads->where('title', 'like', '%' . $search_advert . '%');
}
}
//cf filter arrays
$cf_fields = array();
$cf_user_fields = array();
foreach ($this->request->query() as $name => $field) {
if (isset($field) and $field != NULL) {
// get by prefix cf
if (strpos($name, 'cf_') !== FALSE and array_key_exists(str_replace('cf_', '', $name), Model_Field::get_all())) {
$cf_fields[$name] = $field;
//checkbox when selected return string 'on' as a value
if ($field == 'on') {
$cf_fields[$name] = 1;
} elseif (empty($field)) {
$cf_fields[$name] = NULL;
}
} elseif (strpos($name, 'cfuser_') !== FALSE and array_key_exists(str_replace('cfuser_', '', $name), Model_UserField::get_all())) {
$name = str_replace('cfuser_', 'cf_', $name);
$cf_user_fields[$name] = $field;
//checkbox when selected return string 'on' as a value
if ($field == 'on') {
$cf_user_fields[$name] = 1;
} elseif (empty($field)) {
$cf_user_fields[$name] = NULL;
}
}
}
}
$category = NULL;
$location = NULL;
if (core::config('general.search_multi_catloc') and Theme::$is_mobile === FALSE) {
//filter by category
if (is_array(core::get('category'))) {
$cat_siblings_ids = array();
foreach (core::get('category') as $cat) {
if ($cat !== NULL) {
$category = new Model_Category();
$category->where('seoname', '=', $cat)->cached()->limit(1)->find();
if ($category->loaded()) {
$cat_siblings_ids = array_merge($cat_siblings_ids, $category->get_siblings_ids());
}
}
}
if (count($cat_siblings_ids) > 0) {
$ads->where('id_category', 'IN', $cat_siblings_ids);
}
//.........这里部分代码省略.........
示例4: action_index
public function action_index()
{
if (core::config('general.auto_locate')) {
if ($user_location = Core::post('user_location')) {
Cookie::set('user_location', $user_location);
$this->auto_render = FALSE;
$this->template = View::factory('js');
$this->template->content = TRUE;
return;
} elseif (Core::get('user_location') == '0') {
Cookie::delete('user_location');
}
Theme::$scripts['footer'][] = '//maps.google.com/maps/api/js?sensor=false&libraries=geometry&v=3.7';
Theme::$scripts['footer'][] = '//cdn.jsdelivr.net/gmaps/0.4.15/gmaps.min.js';
}
//template header
$this->template->title = '';
// $this->template->meta_keywords = 'keywords';
if (core::config('general.site_description') != '') {
$this->template->meta_description = core::config('general.site_description');
} else {
$this->template->meta_description = core::config('general.site_name') . ' ' . __('official homepage, get your post listed now.');
}
//setting main view/template and render pages
// get user location if any
$user_location = NULL;
if (is_numeric($user_id_location = Cookie::get('user_location'))) {
$user_location = new Model_Location($user_id_location);
if (!$user_location->loaded()) {
$user_location = NULL;
}
}
// swith to decide on ads_in_home
$ads = new Model_Ad();
$ads->where('status', '=', Model_Ad::STATUS_PUBLISHED);
if ($user_location) {
$ads->where('id_location', 'in', $user_location->get_siblings_ids());
}
$ads_in_home = core::config('advertisement.ads_in_home');
//in case we do not count visits we cant show popular
if (core::config('advertisement.count_visits') == 0 and $ads_in_home == 2) {
$ads_in_home = 0;
}
switch ($ads_in_home) {
case 2:
$id_ads = array_keys(Model_Visit::popular_ads());
if (count($id_ads) > 0) {
$ads->where('id_ad', 'IN', $id_ads);
}
break;
case 1:
$ads->where('featured', 'IS NOT', NULL)->where('featured', '>=', Date::unix2mysql())->order_by('featured', 'desc');
break;
case 4:
$ads->where('featured', 'IS NOT', NULL)->where('featured', '>=', Date::unix2mysql())->order_by(DB::expr('RAND()'));
break;
case 0:
default:
$ads->order_by('published', 'desc');
break;
}
//if ad have passed expiration time dont show
if (core::config('advertisement.expire_date') > 0) {
$ads->where(DB::expr('DATE_ADD( published, INTERVAL ' . core::config('advertisement.expire_date') . ' DAY)'), '>', Date::unix2mysql());
}
$ads = $ads->limit(Theme::get('num_home_latest_ads', 4))->cached()->find_all();
$categs = Model_Category::get_category_count(TRUE, $user_location);
$locats = Model_Location::get_location_count();
$auto_locats = NULL;
$auto_location_distance = Core::config('general.measurement') == 'imperial' ? Num::round(Core::config('advertisement.auto_locate_distance') * 1.60934) : Core::config('advertisement.auto_locate_distance');
if (core::config('general.auto_locate') and !isset($_COOKIE['cancel_auto_locate']) and Model_User::get_userlatlng()) {
$auto_locats = new Model_Location();
$auto_locats = $auto_locats->select(array(DB::expr('degrees(acos(sin(radians(' . $_COOKIE['mylat'] . ')) * sin(radians(`latitude`)) + cos(radians(' . $_COOKIE['mylat'] . ')) * cos(radians(`latitude`)) * cos(radians(abs(' . $_COOKIE['mylng'] . ' - `longitude`))))) * 111.321'), 'distance'))->where('latitude', 'IS NOT', NULL)->where('longitude', 'IS NOT', NULL)->having('distance', '<=', $auto_location_distance)->order_by('distance', 'asc')->find_all()->as_array();
}
$this->template->bind('content', $content);
$this->template->content = View::factory('pages/home', compact('ads', 'categs', 'locats', 'auto_locats', 'user_location'));
}
示例5: format_measurement
/**
* formats measurement system (by defautl metric)
* @param float $number number
* @return string formated measurement
*/
public static function format_measurement($number)
{
if (Core::config('general.measurement') == "imperial") {
$str = Num::round($number * 0.621371192, 1) . ' mi';
} else {
$str = Num::round($number, 1) . ' km';
}
return $str;
}
示例6: sales_by_date
/**
* Returns array with Sales by date formatted to generate charts
* @param timestamp $from_date
* @param timestamp $to_date
* @return array
*/
private function sales_by_date($from_date, $to_date)
{
// Dates range we are filtering
$dates = $this->dates_range($from_date, $to_date);
$query = DB::select(DB::expr('DATE(created) date'))->select(DB::expr('SUM(amount) total'))->from('orders')->where('created', 'between', array(Date::unix2mysql($from_date), Date::unix2mysql($to_date)));
$query = $query->group_by(DB::expr('DATE(created)'))->order_by('date', 'asc')->execute();
$result = $query->as_array('date');
$ret = array();
// print maxinum 30 date labels on charts
$label_counter = 0;
$label_breaker = count($dates) > 30 ? Num::round(count($dates) / 30) : 1;
foreach ($dates as $k => $date) {
$count_sum = isset($result[$date['date']]['total']) ? $result[$date['date']]['total'] : 0;
$ret[] = array('date' => $label_counter % $label_breaker == 0 ? $date['date'] : '', '$' => $count_sum);
$label_counter++;
}
return $ret;
}
示例7: providerRound
public function providerRound()
{
return array(
array(4, Num::round(3.999)),
array(4, Num::round(3.888)),
array(4, Num::round(3.777)),
array(4, Num::round(3.666)),
array(4, Num::round(3.555)),
array(3, Num::round(3.444)),
array(3, Num::round(3.333)),
array(3, Num::round(3.222)),
array(3, Num::round(3.111)),
array(3, Num::round(3.000)),
array(3.555, Num::round(3.555, 4)),
array(3.555, Num::round(3.555, 3)),
array(3.56, Num::round(3.555, 2)),
array(3.6, Num::round(3.555, 1)),
array(4, Num::round(3.555, 0)),
array(4, Num::round(3.5, 0, Num::ROUND_HALF_UP)),
array(3, Num::round(3.5, 0, Num::ROUND_HALF_DOWN)),
array(4, Num::round(3.6, 0, Num::ROUND_HALF_UP)),
array(4, Num::round(3.6, 0, Num::ROUND_HALF_DOWN)),
array(4, Num::round(3.6, 0, Num::ROUND_HALF_EVEN)),
array(4, Num::round(3.6, 0, Num::ROUND_HALF_ODD)),
array(0.6, Num::round(.55, 1, Num::ROUND_HALF_EVEN)),
array(0.5, Num::round(.55, 1, Num::ROUND_HALF_ODD)),
array(0.4, Num::round(.45, 1, Num::ROUND_HALF_EVEN)),
array(0.5, Num::round(.45, 1, Num::ROUND_HALF_ODD)),
array(10, Num::round(9.5, 0, Num::ROUND_HALF_EVEN)),
array(9, Num::round(9.5, 0, Num::ROUND_HALF_ODD)),
);
}