2
Mới! Lưu câu hỏi hoặc câu trả lời và sắp xếp nội dung yêu thích của bạn. Tìm hiểu thêm.
Learn more.
Tôi có một số được lưu trữ trong một biến. Số được lấy từ cơ sở dữ liệu là 9900..Tôi cần chuyển đổi số này thành 99,00 để hiển thị cho khách hàng trong HTML.
Tôi đã tự hỏi làm thế nào tôi có thể đạt được điều này trong PHP.
Thanks.
Hỏi ngày 13 tháng 9 năm 2010 lúc 10:23Sep 13, 2010 at 10:23
109221793109221793109221793
16.1K38 Huy hiệu vàng106 Huy hiệu bạc158 Huy hiệu đồng38 gold badges106 silver badges158 bronze badges
1
$priceInCents = 9900;
$priceInDollars = $priceInCents / 100;
Và sau đó bạn có thể sử dụng round[]
hoặc number_format[]
như bạn muốn.
Đã trả lời ngày 13 tháng 9 năm 2010 lúc 10:25Sep 13, 2010 at 10:25
Bạn có thể sử dụng hàm number_format [] cho điều đó:
echo number_format[9900/100];
Đã trả lời ngày 13 tháng 9 năm 2010 lúc 10:24Sep 13, 2010 at 10:24
2ndkauboy2ndkauboy2ndkauboy
9.2013 huy hiệu vàng28 Huy hiệu bạc64 Huy hiệu đồng3 gold badges28 silver badges64 bronze badges
Woodynadobhar tại Hotmail Dot Com ¶
Dipu dot ashok dot 17 tại gmail dot com ¶ — Format a number with grouped thousands
12 năm trước
Làm thế nào để tôi làm tròn đến 2 số thập phân trong PHP?[
float $num
,
int $decimals
= 0,
?string
$decimal_separator
= ".",
?string $thousands_separator
= ","
]: string
Ví dụ số 1 vòng [] Ví dụ Php Echo Round [3.4]; // 3 Echo Round [3.5]; // 4 Echo Round [3.6]; // 4 vòng lặp [3.6, 0]; // 4 vòng Echo [1.95583, 2]; // 1,96 vòng Echo [1241757, -3]; // 1242000 Echo Round [5.045, 2]; // 5,05 Vòng Echo [5.055, 2]; // 5.06?>
Làm thế nào để tôi nổi một số nguyên trong PHP?Hàm floatVal [] được sử dụng để chuyển đổi giá trị thành phao ..
Phiên bản: [Php 4 trở lên].Cú pháp: floatval [var1].
Tham số: Tên. Sự mô tả. ....Giá trị trả về: Giá trị nổi của biến đã cho ..
Loại giá trị: Float ..Thí dụ : ? ....
Xem thêm. Tham khảo chức năng PHP ..
Trước: trống. Tiếp theo: get_defined_vars ..
Chúng ta có thể sử dụng INT trong PHP không?
8.0.0 | Làm thế nào để tôi làm tròn đến 2 số thập phân trong PHP?number_format[] accepted one, two, or four parameters [but not three]. |
7.2.0 | Ví dụ số 1 vòng [] Ví dụ Php Echo Round [3.4]; // 3 Echo Round [3.5]; // 4 Echo Round [3.6]; // 4 vòng lặp [3.6, 0]; // 4 vòng Echo [1.95583, 2]; // 1,96 vòng Echo [1241757, -3]; // 1242000 Echo Round [5.045, 2]; // 5,05 Vòng Echo [5.055, 2]; // 5.06?> was changed to not being able to return 5, previously 5 could be returned for cases like where num would be 8.
|
Làm thế nào để tôi nổi một số nguyên trong PHP?
Hàm floatVal [] được sử dụng để chuyển đổi giá trị thành phao ..number_format[] Example
Phiên bản: [Php 4 trở lên].
echo number_format[9900/100];
9round[]
0
round[]
1Xem thêm
- money_format [] - định dạng một số dưới dạng chuỗi tiền tệ
- Sprintf [] - Trả về chuỗi được định dạng
- printf [] - đầu ra chuỗi được định dạng
- sscanf [] - đầu vào phân tích cú pháp từ một chuỗi theo định dạng
Thomas tại Weblizards Dot de ¶ ¶
13 năm trước
round[]
2
round[]
3
round[]
4Thông tin tại Ensostudio Dot Ru ¶ ¶
9 tháng trước
round[]
5
James tại Bandit Dot Co.NZ ¶ ¶
13 năm trước
round[]
6
round[]
7
round[]
8
round[]
9Thông tin tại Ensostudio Dot Ru ¶ ¶
9 tháng trước
number_format[]
0
number_format[]
1
number_format[]
2
number_format[]
3
number_format[]
4
number_format[]
5
round[]
4James tại Bandit Dot Co.NZ ¶ ¶
Marcm ¶
number_format[]
7
number_format[]
8
number_format[]
9
round[]
416 năm trước ¶
STM555 tại hotmail dot com
$num
1
$num
2
round[]
417 năm trước ¶
13 năm trước
$num
4
$num
5
$num
6
$num
7
$num
8Thông tin tại Ensostudio Dot Ru ¶ ¶
9 tháng trước
$num
9
$decimals
0
$decimals
1
round[]
4James tại Bandit Dot Co.NZ ¶ ¶
Marcm ¶
$decimals
3
$decimals
4
$decimals
516 năm trước ¶
STM555 tại hotmail dot com
$decimals
6
$decimals
7
$decimals
8
$decimals
9
round[]
417 năm trước ¶
Marcm ¶
$decimal_separator
1
$decimal_separator
2
round[]
416 năm trước ¶
9 tháng trước
$decimal_separator
4
$decimal_separator
5
$decimal_separator
6
round[]
4James tại Bandit Dot Co.NZ ¶ ¶
Marcm ¶
$decimal_separator
8
$decimal_separator
9
$thousands_separator
0
$thousands_separator
116 năm trước ¶
STM555 tại hotmail dot com
$thousands_separator
2
$thousands_separator
3
$thousands_separator
4
$thousands_separator
5
$thousands_separator
6
$thousands_separator
7
$thousands_separator
8
$thousands_separator
9
num
0
num
1
num
2
num
3
num
4
num
5
num
6
num
7
num
8
num
9
decimals
0
decimals
1
round[]
417 năm trước ¶
Lio ¶
decimals
3
decimals
4
round[]
44 năm trước ¶
Nospam tại Nospam Dot Com ¶
decimals
6
SGJ tại Tiến sĩ Dot Com ¶ ¶
19 năm trước
decimals
7
decimals
8
decimals
9
echo number_format[9900/100];
00echo number_format[9900/100];
01echo number_format[9900/100];
02echo number_format[9900/100];
03echo number_format[9900/100];
04round[]
4Tomislav tại Firmus-Grupa Dot HR ¶ ¶
9 năm trước
echo number_format[9900/100];
06echo number_format[9900/100];
07echo number_format[9900/100];
08echo number_format[9900/100];
09Thông tin tại Ensostudio Dot Ru ¶ ¶
9 tháng trước
echo number_format[9900/100];
10James tại Bandit Dot Co.NZ ¶ ¶
13 năm trước
echo number_format[9900/100];
11echo number_format[9900/100];
12echo number_format[9900/100];
13echo number_format[9900/100];
14echo number_format[9900/100];
15echo number_format[9900/100];
16Thông tin tại Ensostudio Dot Ru ¶ ¶
9 tháng trước
echo number_format[9900/100];
17echo number_format[9900/100];
18echo number_format[9900/100];
19echo number_format[9900/100];
20round[]
4James tại Bandit Dot Co.NZ ¶ ¶
9 tháng trước
echo number_format[9900/100];
22echo number_format[9900/100];
23echo number_format[9900/100];
24echo number_format[9900/100];
25round[]
4James tại Bandit Dot Co.NZ ¶ ¶
Marcm ¶
echo number_format[9900/100];
27echo number_format[9900/100];
28round[]
416 năm trước ¶
STM555 tại hotmail dot com
echo number_format[9900/100];
30echo number_format[9900/100];
31echo number_format[9900/100];
32echo number_format[9900/100];
33round[]
417 năm trước ¶
Lio ¶
echo number_format[9900/100];
35echo number_format[9900/100];
36echo number_format[9900/100];
37round[]
44 năm trước ¶
13 năm trước
echo number_format[9900/100];
39echo number_format[9900/100];
40echo number_format[9900/100];
41round[]
4Thông tin tại Ensostudio Dot Ru ¶ ¶
13 năm trước
echo number_format[9900/100];
43echo number_format[9900/100];
44echo number_format[9900/100];
45echo number_format[9900/100];
46round[]
4Thông tin tại Ensostudio Dot Ru ¶ ¶
STM555 tại hotmail dot com
echo number_format[9900/100];
48echo number_format[9900/100];
49round[]
417 năm trước ¶
Lio ¶
echo number_format[9900/100];
51echo number_format[9900/100];
52round[]
44 năm trước ¶
Lio ¶
echo number_format[9900/100];
54echo number_format[9900/100];
55round[]
44 năm trước ¶
Marcm ¶
echo number_format[9900/100];
57echo number_format[9900/100];
58round[]
416 năm trước ¶
Marcm ¶
echo number_format[9900/100];
60echo number_format[9900/100];
61round[]
416 năm trước ¶
STM555 tại hotmail dot com
echo number_format[9900/100];
63echo number_format[9900/100];
64echo number_format[9900/100];
65echo number_format[9900/100];
6617 năm trước ¶
13 năm trước
echo number_format[9900/100];
67echo number_format[9900/100];
68echo number_format[9900/100];
69round[]
4Lio ¶ ¶
Marcm ¶
echo number_format[9900/100];
71echo number_format[9900/100];
72round[]
416 năm trước ¶
STM555 tại hotmail dot com
echo number_format[9900/100];
74echo number_format[9900/100];
75round[]
4