參考網址:
http://fanli7.net/a/bianchengyuyan/PHP/20100930/40653.html
http://blog.hsin.tw/2009/php-pad-a-string/
最近做了一個案子非台幣為貨幣,因此會有小數點的問題。
我想實作出紙個網站是統一格式。
例:
$85.5統一顯示$85.50
$80統一顯示$80.00
但php 直接 echo 卻無法呈現我想要的效果
他只會顯示85.5.......這不是我要的阿...
於是爬了文找到補零方法
我的需求是要做到小數二位數因此要這麼做..
$money=85.5
echo sprintf(”%01.2f”,$money); //會印出85.50
成功!!
相關文章:
- [php]小數點不足補零
- [php]數字金額轉中文大寫金額
- [php]將數字每隔三位加上逗號number_format
--
dizzy03 發表在 痞客邦 留言(0) 人氣()
非static參數使用方式為$this->參數名稱
ex: $this->aaa;
dizzy03 發表在 痞客邦 留言(0) 人氣()
dizzy03 發表在 痞客邦 留言(0) 人氣()
最近遇到dataTable使用complex header匯出只會匯出最後一行header的問題
找到的方法是要手動修改buttons.html5.js內容
dizzy03 發表在 痞客邦 留言(0) 人氣()
[php]strpos — 查找字符串首次出现的位置
官方範例1
<?php
$mystring = 'abc';
$findme = 'a';
$pos = strpos($mystring, $findme);
// 注意這裡使用的是 ===。簡單的 == 不能像我們期待的那樣工作,
// 因為 'a' 是第 0 位置上的(第一個)字符。
if ($pos === false) {
echo "The string '$findme' was not found in the string '$mystring'";
} else {
echo "The string '$findme' was found in the string '$mystring'";
echo " and exists at position $pos";
}
?>
官方範例2
<?php
$mystring = 'abc';
$findme = 'a';
$pos = strpos($mystring, $findme);
// 使用 !== 操作符。使用 != 不能像我們期待的那樣工作,
// 因為 'a' 的位置是 0。語句 (0 != false) 的結果是 false。
if ($pos !== false) {
echo "The string '$findme' was found in the string '$mystring'";
echo " and exists at position $pos";
} else {
echo "The string '$findme' was not found in the string '$mystring'";
}
?>
官方範例3
<?php
// 忽視位置偏移量之前的字符進行查找
$newstring = 'abcdef abcdef';
$pos = strpos($newstring, 'a', 1); // $pos = 7, 不是 0
?>
--
dizzy03 發表在 痞客邦 留言(0) 人氣()
這是一個不錯的PHP 縮圖程式,找到的時候好興奮說
使用上很方便,只要照著自己需求去設定就可以囉
dizzy03 發表在 痞客邦 留言(0) 人氣()
最近在維護程式碼的時候,發現有一段刪除目錄以下全部檔案的 code。
dizzy03 發表在 痞客邦 留言(0) 人氣()
注意:Laravel使用try catch要先use Exception;
否則會出現 Class 'App\Http\Controllers\Exception' not found 的 error msg
dizzy03 發表在 痞客邦 留言(0) 人氣()
"drawCallback": function( settings ) {
dizzy03 發表在 痞客邦 留言(0) 人氣()
Q:
我正在爲一個站點編寫一個預先編寫的模塊,並且我需要定位一個ID爲test:two
的元素。現在,這個元素有一個冒號,所以jquery大概可以理解地把'two'看作一個僞類。有什麼方法可以用jQuery來定位這個元素嗎?jquery選擇一個帶有冒號的ID
dizzy03 發表在 痞客邦 留言(0) 人氣()