本文整理汇总了PHP中number_format函数的典型用法代码示例。如果您正苦于以下问题:PHP number_format函数的具体用法?PHP number_format怎么用?PHP number_format使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了number_format函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: smsSend
/**
* @param $phone
* @param $code
* @return bool
* send sms to register&runner phone
*/
private function smsSend($phone, $code)
{
$account = "mt6724";
$password = "le44n8";
$time = microtime();
$time = explode(" ", $time);
$time = $time[1] + $time[0];
$time = number_format($time * 1000, 0, ".", "");
$timestamp = $time;
$access_token = md5($timestamp . $password);
$receive = $phone;
$smscontent = "你的验证码为{$code},有效期10分钟";
$str = "account={$account}×tamp={$timestamp}&access_token={$access_token}&receiver={$receive}&smscontent={$smscontent}&extcode=0";
$url = "http://121.42.11.93:8001/interface/sendSms";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
// post数据
curl_setopt($ch, CURLOPT_POST, 1);
// post的变量
curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
$output = curl_exec($ch);
curl_close($ch);
$res = json_decode($output, TRUE);
if ($res['res_code'] == '0') {
return true;
} else {
return false;
}
}
示例2: example_output
function example_output($content)
{
$content = trim($content);
echo PHP_EOL . $content . PHP_EOL . PHP_EOL;
echo '# Sir\'s template is rendered above (';
echo number_format(strlen($content)) . ' bytes).' . PHP_EOL;
}
示例3: pretty_number
function pretty_number($n, $floor = true)
{
if ($floor) {
$n = floor($n);
}
return number_format($n, 0, ",", ".");
}
示例4: getSummary
/**
* @inheritdoc
*/
public function getSummary()
{
$timings = $this->calculateTimings();
$queryCount = count($timings);
$queryTime = number_format($this->getTotalQueryTime($timings) * 1000) . ' ms';
return Yii::$app->view->render('panels/db/summary', ['timings' => $this->calculateTimings(), 'panel' => $this, 'queryCount' => $queryCount, 'queryTime' => $queryTime]);
}
示例5: timer
/**
* Measure time between two events
*
* First call should be to $key = Debug::timer() with no params, or provide your own key that's not already been used
* Second call should pass the key given by the first call to get the time elapsed, i.e. $time = Debug::timer($key).
* Note that you may make multiple calls back to Debug::timer() with the same key and it will continue returning the
* elapsed time since the original call. If you want to reset or remove the timer, call removeTimer or resetTimer.
*
* @param string $key
* Leave blank to start timer.
* Specify existing key (string) to return timer.
* Specify new made up key to start a named timer.
* @param bool $reset If the timer already exists, it will be reset when this is true.
* @return string|int
*
*/
public static function timer($key = '', $reset = false)
{
// returns number of seconds elapsed since first call
if ($reset && $key) {
self::removeTimer($key);
}
if (!$key || !isset(self::$timers[$key])) {
// start new timer
preg_match('/(\\.[0-9]+) ([0-9]+)/', microtime(), $time);
$startTime = doubleval($time[1]) + doubleval($time[2]);
if (!$key) {
$key = $startTime;
while (isset(self::$timers[$key])) {
$key .= ".";
}
}
self::$timers[$key] = $startTime;
$value = $key;
} else {
// return timer
preg_match('/(\\.[0-9]*) ([0-9]*)/', microtime(), $time);
$endTime = doubleval($time[1]) + doubleval($time[2]);
$startTime = self::$timers[$key];
$runTime = number_format($endTime - $startTime, 4);
$value = $runTime;
}
return $value;
}
示例6: taksitHesapla
/**
* Verilen taksit
*
* @param float $fiyat
* @param integer $taksitSayisi
* @return float
*/
public function taksitHesapla($fiyat, $taksitSayisi)
{
if (!isset($this->vadeFarklari[$taksitSayisi])) {
return false;
}
return number_format(($this->vadeFarklari[$taksitSayisi] + 100) * $fiyat / 100, 2, '.', '');
}
示例7: call_order
function call_order($lng, $para, $filename = 'order', $outHTML = null)
{
$para = $this->fun->array_getvalue($para);
$lngpack = $lng ? $lng : $this->CON['is_lancode'];
$lng = $lng == 'big5' ? $this->CON['is_lancode'] : $lng;
include admin_ROOT . 'datacache/' . $lng . '_pack.php';
$cartid = $this->fun->eccode($this->fun->accept('ecisp_order_list', 'C'), 'DECODE', db_pscode);
$cartid = stripslashes(htmlspecialchars_decode($cartid));
$uncartid = !empty($cartid) ? unserialize($cartid) : null;
$total = $this->fun->eccode($this->fun->accept('ecisp_order_productmoney', 'C'), 'DECODE', db_pscode);
$total = empty($total) ? 0 : $total;
$buylink = $this->get_link('order', array(), $lngpack);
$this->pagetemplate->assign('lngpack', $LANPACK);
$this->pagetemplate->assign('buylink', $buylink);
$this->pagetemplate->assign('ordertotal', number_format($total, 2));
$this->pagetemplate->assign('total', $total);
$this->pagetemplate->assign('uncartid', count($uncartid));
$this->pagetemplate->assign('cartid', $cartid);
if (!empty($outHTML)) {
$output = $this->pagetemplate->fetch(null, null, $outHTML);
} else {
$output = $this->pagetemplate->fetch($lng . '/lib/' . $filename);
}
return $output;
}
示例8: TampilkanDaftarProgramStudi
function TampilkanDaftarProgramStudi()
{
global $Cari;
$Max = 50;
$arrcr = explode(',', $Cari);
$arrwhr = array();
if (!empty($arrcr[0])) {
$arrwhr[] = "(Nama like '%" . TRIM($arrcr[0]) . "%') ";
}
$whr = implode(' and ', $arrwhr);
// Hitung jumlah baris
$Jml = GetaField('perguruantinggi', "{$whr} and NA", 'N', "count(PerguruanTinggiID)");
if ($Jml > $Max) {
$_Jml = number_format($Jml);
echo "<p><b>Catatan:</b> Jumlah program studi yang Anda cari mencapai: <b>{$_Jml}</b>, tetapi sistem membatasi\r\n jumlah program studi yang ditampilkan dan hanya menampilkan: <b>{$Max}</b>.\r\n Gunakan Nama program studi dengan lebih spesifik untuk membatasi\r\n jumlah program studi yang ditampilkan.</p>\r\n\r\n <p><b>Format Pencarian:</b> NamaProgramStudi</p>";
}
// Tampilkan
$s = "select ProdiDiktiID, Nama\r\n from prodidikti\r\n where {$whr} and NA='N'\r\n order by Nama limit {$Max}";
$r = _query($s);
$n = 0;
echo "<p><table class=box cellspacing=1 cellpadding=4 width=100%>\r\n <tr><th class=ttl>#</th>\r\n <th class=ttl>Kode Prodi</th>\r\n <th class=ttl>Nama</th>\r\n </tr>";
while ($w = _fetch_array($r)) {
$n++;
echo "<tr><td class=ul>{$n}</td>\r\n <td class=ul><a href='javascript:kembalikan(\"{$w['ProdiDiktiID']}\", \"{$w['Nama']}\")'>{$w['ProdiDiktiID']}</a></td>\r\n <td class=ul>{$w['Nama']} </td>\r\n </tr>";
}
echo "</table></p>";
}
示例9: getUrl
public function getUrl()
{
$this->addField('CustomerID', $this->getConfigValue('customerID'));
$this->addField('UserName', $this->getConfigValue('userName'));
$this->addField('Amount', number_format($this->details->amount->get(), 2, '.', ''));
$this->addField('Currency', $this->details->currency->get());
// customer information
$this->addField('CustomerEmail', $this->details->email->get());
$this->addField('CustomerFirstName', $this->details->firstName->get());
$this->addField('CustomerLastName', $this->details->lastName->get());
$this->addField('CustomerAddress', $this->details->address->get());
$this->addField('CustomerCity', $this->details->city->get());
$this->addField('CustomerState', $this->details->state->get());
$this->addField('CustomerPostcode', $this->details->postalCode->get());
$this->addField('CustomerCountry', $this->details->country->get());
$this->addField('MerchantOption1', $this->returnUrl);
$this->addField('MerchantOption2', $this->details->currency->get());
$this->addField('MerchantOption3', '');
$this->addField('InvoiceDescription', $this->getConfigValue('invoiceDescription'));
// order information
$this->addField('MerchantReference', $this->details->invoiceID->get());
$this->addField('CancelUrl', $this->siteUrl);
$this->addField('ReturnUrl', $this->notifyUrl);
preg_match('/URI>(.*)<\\/URI>/', $this->fetchUrl($this->getRequestUrl()), $match);
return array_pop($match);
}
示例10: getLoveHistory
public function getLoveHistory($page, $justUser = false)
{
$front = Frontend::getInstance();
$page--;
$l = $this->getLimit() * $page;
$where = '';
$sql = "SELECT count(*) " . "FROM " . LOVE_LOVE;
$res = mysql_query($sql);
$row = mysql_fetch_row($res);
$loves = $row[0];
$sql = "SELECT count(*) " . "FROM " . LOVE_LOVE . " " . "WHERE " . LOVE_LOVE . ".receiver = '" . $front->getUser()->getUsername() . "' " . "OR " . LOVE_LOVE . ".giver = '" . $front->getUser()->getUsername() . "' " . ($sql .= $justUser ? '' : "OR " . LOVE_LOVE . ".company_id = '" . $front->getUser()->getCompany_id() . "' ");
$sql .= $where . " " . "ORDER BY id DESC";
$res = mysql_query($sql);
$row = mysql_fetch_row($res);
$count = $row[0];
$cPages = ceil($count / $this->getLimit());
$sql = "SELECT id,giver,receiver,why,private,TIMESTAMPDIFF(SECOND,at,NOW()) as delta " . "FROM " . LOVE_LOVE . " " . "WHERE " . LOVE_LOVE . ".receiver = '" . $front->getUser()->getUsername() . "' " . "OR " . LOVE_LOVE . ".giver = '" . $front->getUser()->getUsername() . "' ";
$sql .= $justUser ? '' : "OR " . LOVE_LOVE . ".company_id = '" . $front->getUser()->getCompany_id() . "' ";
$sql .= $where . " " . "ORDER BY id DESC " . "LIMIT " . $l . "," . $this->getLimit();
$res = mysql_query($sql);
// Construct json for history
$this->pages = array(array($page, $cPages, number_format($loves)));
for ($i = 1; $row = mysql_fetch_assoc($res); $i++) {
$givernickname = getNickName($row['giver']);
$givernickname = !empty($givernickname) ? $givernickname : $row['giver'];
$receivernickname = getNickName($row['receiver']);
$receivernickname = !empty($receivernickname) ? $receivernickname : $row['receiver'];
$why = $row['why'];
if ($row['private']) {
$why .= " (love sent quietly)";
}
$history[] = array("id" => $row['id'], "giver" => $row['giver'], "giverNickname" => $givernickname, "receiver" => $row['receiver'], "receiverNickname" => $receivernickname, "why" => $why, "delta" => Utils::relativeTime($row['delta']));
}
return $history;
}
示例11: bjtable
function bjtable($res, $frame_caption)
{
$htmlout = '';
$htmlout .= begin_frame($frame_caption, true);
$htmlout .= begin_table();
$htmlout .= "<tr>\r\n\t<td class='colhead'>Rank</td>\r\n\t<td class='colhead' align='left'>User</td>\r\n\t<td class='colhead' align='right'>Wins</td>\r\n\t<td class='colhead' align='right'>Losses</td>\r\n\t<td class='colhead' align='right'>Games</td>\r\n\t<td class='colhead' align='right'>Percentage</td>\r\n\t<td class='colhead' align='right'>Win/Loss</td>\r\n\t</tr>";
$num = 0;
while ($a = mysqli_fetch_assoc($res)) {
++$num;
//==Calculate Win %
$win_perc = number_format($a['wins'] / $a['games'] * 100, 1);
//==Add a user's +/- statistic
$plus_minus = $a['wins'] - $a['losses'];
if ($plus_minus >= 0) {
$plus_minus = mksize(($a['wins'] - $a['losses']) * 100 * 1024 * 1024);
} else {
$plus_minus = "-";
$plus_minus .= mksize(($a['losses'] - $a['wins']) * 100 * 1024 * 1024);
}
$htmlout .= "<tr><td>{$num}</td><td align='left'>" . "<b><a href='userdetails.php?id=" . $a['id'] . "'>" . $a['username'] . "</a></b></td>" . "<td align='right'>" . number_format($a['wins'], 0) . "</td>" . "<td align='right'>" . number_format($a['losses'], 0) . "</td>" . "<td align='right'>" . number_format($a['games'], 0) . "</td>" . "<td align='right'>{$win_perc}</td>" . "<td align='right'>{$plus_minus}</td>" . "</tr>\n";
}
$htmlout .= end_table();
$htmlout .= end_frame();
return $htmlout;
}
示例12: run
/**
* Run
*/
public function run()
{
// Authenticate
$this->authenticate();
// Failed to get account details
if (!($account = $this->api->getAccount())) {
$this->abort('Unable to fetch account');
}
// Get last workspace
$workspace = $account->getLastWorkspace();
// Get summary report for all hours
$summary = $this->api->getMemberTimesheetReport($workspace, $account);
// Account
$this->line();
$this->line('Account:');
$this->line(' %-15s: %s', 'Id', $account->getId());
$this->line(' %-15s: %s', 'Created', date('Y-m-d H:i', $account->getCreatedTime()));
$this->line(' %-15s: %s', 'Last workspace', $account->getLastWorkspaceId());
$this->line(' %-15s: %s', 'Company', $workspace->getCompanyName());
$this->line(' %-15s: %s', 'First Name', $account->getFirstName());
$this->line(' %-15s: %s', 'Last Name', $account->getLastName());
$this->line(' %-15s: %s', 'Email', $account->getEmailAddress());
$this->line();
// Hours summary
$this->line('Hours:');
$this->line(' %-15s: %s', 'Expected', number_format($summary->getRequiredHours(), 2));
$this->line(' %-15s: %s', 'Logged', number_format($summary->getLoggedHours(), 2));
$this->line(' %-15s: %s', 'Unlogged', number_format($summary->getUnloggedHours(), 2));
$this->line(' %-15s: %s', 'Summed', number_format($summary->getTotalHours(), 2));
$this->line(' %-15s: %s', 'Offset', ($summary->getOffsetHours() > 0 ? '+' : '') . number_format($summary->getOffsetHours(), 2));
$this->line();
}
示例13: sendVariables
function sendVariables($path_url, $pp_vals)
{
$this->_POST1 = array();
$this->_POST1['instId'] = $pp_vals['wp_instId'];
$this->_POST1['item_number'] = time() . rand(0, 1000);
if (isset($_POST['force_inv_no'])) {
$this->_POST1['item_number'] = $_POST['force_inv_no'];
}
$this->_POST1['cartId'] = $this->_POST1['item_number'];
$this->_POST1['amount'] = number_format($_POST['gross_amount'], 2);
$this->_POST1['currency'] = $pp_vals['wp_currency'];
$this->_POST1['desc'] = $_POST['desc'];
if ($this->demo_mode) {
$this->_POST1['testMode'] = 100;
}
$this->_POST1['M_pp'] = "WorldPay";
$this->_POST1['M_item_no'] = $this->_POST1['item_number'];
$this->_POST1['name'] = $_POST['name'];
$this->_POST1['tel'] = $_POST['telephone'];
$this->_POST1['address'] = $_POST['address'];
$this->_POST1['city'] = $_POST['city'];
$this->_POST1['state'] = $_POST['state'];
$this->_POST1['postcode'] = $_POST['zip'];
$this->_POST1['country'] = $_POST['country'];
$this->_POST1['email'] = $_POST['email'];
}
示例14: format
/**
* Returns the given amount as a formatted string according to the
* given currency.
* IMPORTANT NOTE:
* The amount must always be the smallest unit passed as a string
* or int! It is a very bad idea to use float for monetary
* calculations if you need exact values, therefore
* this method won't accept float values.
* Examples:
* format (500, 'EUR'); --> '5,00 EUR'
* format (4.23, 'EUR'); --> FALSE
* format ('872331', 'EUR'); --> '8.723,31 EUR'.
*
* @param int|string $amount Amount to be formatted. Must be the smalles unit
* @param string $currencyKey ISO 3 letter code of the currency
* @param bool $withSymbol If set the currency symbol will be rendered
*
* @return string|bool String representation of the amount including currency
* symbol(s) or FALSE if $amount was of the type float
*/
public static function format($amount, $currencyKey, $withSymbol = true)
{
if (is_float($amount)) {
return false;
}
/**
* Currency repository.
*
* @var CurrencyRepository
*/
$currencyRepository = GeneralUtility::makeInstance('CommerceTeam\\Commerce\\Domain\\Repository\\CurrencyRepository');
$currency = $currencyRepository->findByIso3($currencyKey);
if (empty($currency)) {
return false;
}
$formattedAmount = number_format($amount / $currency['cu_sub_divisor'], $currency['cu_decimal_digits'], $currency['cu_decimal_point'], $currency['cu_thousands_point']);
if ($withSymbol) {
$wholeString = $formattedAmount;
if (!empty($currency['cu_symbol_left'])) {
$wholeString = $currency['cu_symbol_left'] . ' ' . $wholeString;
}
if (!empty($currency['cu_symbol_right'])) {
$wholeString .= ' ' . $currency['cu_symbol_right'];
}
} else {
$wholeString = $formattedAmount;
}
return $wholeString;
}
示例15: json_encode
function json_encode($data)
{
if (is_array($data)) {
$ret = array();
// OBJECT
if (array_keys($data) !== range(0, count($data) - 1)) {
foreach ($data as $key => $val) {
$ret[] = kcfinder_json_string_encode($key) . ':' . json_encode($val);
}
return "{" . implode(",", $ret) . "}";
// ARRAY
} else {
foreach ($data as $val) {
$ret[] = json_encode($val);
}
return "[" . implode(",", $ret) . "]";
}
// BOOLEAN OR NULL
} elseif (is_bool($data) || $data === null) {
return $data === null ? "null" : ($data ? "true" : "false");
} elseif (is_float($data)) {
return rtrim(rtrim(number_format($data, 14, ".", ""), "0"), ".");
} elseif (is_int($data)) {
return $data;
}
// STRING
return kcfinder_json_string_encode($data);
}