2011-01-24 64 views

回答

2

是的,它被稱爲number_format。您的案例中的示例用法:

echo number_format(1, 2, '.', ''); 

will echo 1.00。現在,用它查詢插入,環繞它的報價和做這樣的:

mysql_query("INSERT INTO tablename (Amount) 
      VALUES ('" . number_format($your_number), 2, '.', '') . "')"; 
+0

`number_format()`的返回值是一個字符串,因此可能無法解決OP的問題。 – jeroen 2011-01-24 15:40:23

+0

此代碼工作,謝謝你的例子;)我只能在7分鐘內點擊打勾。 – DogPooOnYourShoe 2011-01-24 15:43:20

+0

因爲SQL本身就是一個字符串,所以他是否準確地準備了他的語句並不重要。 – 2011-01-24 15:43:45

0

它爲什麼會拒絕呢?你用引號或其他東西包裝它?無論如何,要轉換,使用number_format()函數。

1

可以投下數爲float例如像:

$x = (float) $x; 

或:

$x = floatval($x); 
0

你可以做到這一點

$num = 1; 
print number_format($num , 2); 
相關問題