Hướng dẫn how to remove digits after decimal in php - cách xóa các chữ số sau số thập phân trong php

Ví dụ: 1.123 => 1 1.999 => 1

thanks.

Khi được hỏi ngày 15 tháng 5 năm 2010 lúc 17:45May 15, 2010 at 17:45

Hướng dẫn how to remove digits after decimal in php - cách xóa các chữ số sau số thập phân trong php

Lovespringlovespringlovespring

Phim thương hiệu vàng 18,5K4141 gold badges99 silver badges150 bronze badges

0

$y = 1.235251;
$x = (int)$y;
echo $x; //will echo "1"

EDIT: Sử dụng diễn viên rõ ràng đến (int) là cách hiệu quả nhất cho AFAIK này. Cũng đúc đến (int) sẽ cắt các chữ số sau "." Nếu số là âm thay vì làm tròn đến số âm thấp hơn tiếp theo: Using the explicit cast to (int) is the most efficient way to to this AFAIK. Also casting to (int) will cut off the digits after the "." if the number is negative instead of rounding to the next lower negative number:

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";

Đã trả lời ngày 15 tháng 5 năm 2010 lúc 17:47May 15, 2010 at 17:47

Hướng dẫn how to remove digits after decimal in php - cách xóa các chữ số sau số thập phân trong php

SelfawaresoupSelfawaresoupselfawaresoup

15.1k7 Huy hiệu vàng35 Huy hiệu bạc47 Huy hiệu đồng7 gold badges35 silver badges47 bronze badges

3

floor() 

sẽ làm tròn một số xuống số nguyên gần nhất.

Chỉnh sửa: Như được chỉ ra bởi Mark dưới đây, điều này sẽ chỉ hoạt động cho các giá trị tích cực, đó là một giả định quan trọng. Đối với các giá trị âm, bạn muốn sử dụng ceil() - nhưng kiểm tra dấu hiệu của giá trị đầu vào sẽ rất cồng kềnh và có lẽ bạn muốn sử dụng ý tưởng ____10 của Mark hoặc Technop. Hy vọng điều đó sẽ giúp.

Đã trả lời ngày 15 tháng 5 năm 2010 lúc 17:47May 15, 2010 at 17:47

1

SelfawaresoupSelfawaresoup

Without:

echo 49 / 3;
>> 16.333333333333

15.1k7 Huy hiệu vàng35 Huy hiệu bạc47 Huy hiệu đồng| 0" bitwise:

echo 49 / 3 | 0;
>> 16

sẽ làm tròn một số xuống số nguyên gần nhất.Nov 27, 2013 at 1:20

Chỉnh sửa: Như được chỉ ra bởi Mark dưới đây, điều này sẽ chỉ hoạt động cho các giá trị tích cực, đó là một giả định quan trọng. Đối với các giá trị âm, bạn muốn sử dụng ceil() - nhưng kiểm tra dấu hiệu của giá trị đầu vào sẽ rất cồng kềnh và có lẽ bạn muốn sử dụng ý tưởng ____10 của Mark hoặc Technop. Hy vọng điều đó sẽ giúp.Rafalages

Bạn có thể sử dụng một toán tử bitwise.1 gold badge9 silver badges19 bronze badges

1

$y = 1.234;
list($y) = explode(".", "$y");

Hướng dẫn how to remove digits after decimal in php - cách xóa các chữ số sau số thập phân trong php

Với "| 0" bitwise:May 15, 2010 at 17:53

Hướng dẫn how to remove digits after decimal in php - cách xóa các chữ số sau số thập phân trong php

Đã trả lời ngày 27 tháng 11 năm 2013 lúc 1:20nothrow

Rafalagesrafalages8 gold badges55 silver badges101 bronze badges

1

1.2961 Huy hiệu vàng9 Huy hiệu bạc19 Huy hiệu đồng

floor(1.2)

Đã trả lời ngày 15 tháng 5 năm 2010 lúc 17:53

(int)-1.2

nothrownothrowMay 15, 2010 at 17:58

15.5k8 Huy hiệu vàng55 Huy hiệu bạc101 Huy hiệu ĐồngMark Byers

Nếu đầu vào của bạn chỉ có thể là phao tích cực thì tầng đã được đề cập hoạt động.184 gold badges1552 silver badges1440 bronze badges

6

Tuy nhiên, nếu số nguyên của bạn cũng có thể âm thì sàn có thể không cung cấp cho bạn những gì bạn muốn: nó luôn làm tròn ngay cả đối với các số âm. Thay vào đó bạn có thể chọn vào Int như một bài viết khác đã đề cập. Điều này sẽ cung cấp cho bạn kết quả chính xác cho cả số âm và dương.

echo round(51.5); // Round the number, return 51.
echo floor(51.5); // Round down number, return 51.
echo ceil(51.3); // Round up number, return 52.

Đã trả lời ngày 15 tháng 5 năm 2010 lúc 17:58Apr 13, 2018 at 11:15

Hướng dẫn how to remove digits after decimal in php - cách xóa các chữ số sau số thập phân trong php

Mark Byersmark ByersShorabh

782K184 Huy hiệu vàng1552 Huy hiệu bạc1440 Huy hiệu đồng2 silver badges9 bronze badges

thần thánh76 tại gmail dot com ¶

Thư tại Igor Dot Vodka ¶Format a number with grouped thousands

3 năm trước

Svein Tjonndal (Sveint tại Yahoo Dot Com) ¶(
    float

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
1,
    int
echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
2 = 0
,
    ?string
echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
3 = "."
,
    ?string
echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
4 = ","

): string

18 năm trước

Mobi Dot Lenoe tại Gmail Dot Com ¶

8 năm trước

IMSOP ¶

Barbara ¶

Gabrielu tại gmail dot com ¶

uliciadrian01 tại yahoo dot com ¶

quản trị trang web tại www.ellesseweb.net ¶

Jeroen de Bruijn [NL]

Marc dot vanwoerkom tại Fernuni-Hagen Dot de ¶

Ali Okan Yksel ¶

11 năm trước

Samuelpeixoto tại Gmail Dot Com ¶3 năm trước
8.0.0 Svein Tjonndal (Sveint tại Yahoo Dot Com) ¶number_format() accepted one, two, or four parameters (but not three).
7.2.0 18 năm trước was changed to not being able to return
floor() 
2, previously
floor() 
2 could be returned for cases like where
echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
5 would be
floor() 
5.

Mobi Dot Lenoe tại Gmail Dot Com ¶

8 năm trướcnumber_format() Example

IMSOP ¶

floor() 
6

floor() 
7

floor() 
8

Xem 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

floor() 
9

echo 49 / 3;
>> 16.333333333333
0

echo 49 / 3;
>> 16.333333333333
1

Thông tin tại Ensostudio Dot Ru ¶

9 tháng trước

echo 49 / 3;
>> 16.333333333333
2

James tại Bandit Dot Co.NZ ¶

13 năm trước

echo 49 / 3;
>> 16.333333333333
3

echo 49 / 3;
>> 16.333333333333
4

echo 49 / 3;
>> 16.333333333333
5

echo 49 / 3;
>> 16.333333333333
6

Thông tin tại Ensostudio Dot Ru ¶

9 tháng trước

echo 49 / 3;
>> 16.333333333333
7

echo 49 / 3;
>> 16.333333333333
8

echo 49 / 3;
>> 16.333333333333
9

echo 49 / 3 | 0;
>> 16
0

echo 49 / 3 | 0;
>> 16
1

echo 49 / 3 | 0;
>> 16
2

echo 49 / 3;
>> 16.333333333333
1

James tại Bandit Dot Co.NZ ¶

Marcm ¶

echo 49 / 3 | 0;
>> 16
4

echo 49 / 3 | 0;
>> 16
5

echo 49 / 3 | 0;
>> 16
6

echo 49 / 3;
>> 16.333333333333
1

16 năm trước

STM555 tại hotmail dot com

echo 49 / 3 | 0;
>> 16
8

echo 49 / 3 | 0;
>> 16
9

echo 49 / 3;
>> 16.333333333333
1

17 năm trước

13 năm trước

$y = 1.234;
list($y) = explode(".", "$y");
1

$y = 1.234;
list($y) = explode(".", "$y");
2

$y = 1.234;
list($y) = explode(".", "$y");
3

$y = 1.234;
list($y) = explode(".", "$y");
4

$y = 1.234;
list($y) = explode(".", "$y");
5

Thông tin tại Ensostudio Dot Ru ¶

9 tháng trước

$y = 1.234;
list($y) = explode(".", "$y");
6

$y = 1.234;
list($y) = explode(".", "$y");
7

$y = 1.234;
list($y) = explode(".", "$y");
8

echo 49 / 3;
>> 16.333333333333
1

James tại Bandit Dot Co.NZ ¶

Marcm ¶

floor(1.2)
0

floor(1.2)
1

floor(1.2)
2

16 năm trước

STM555 tại hotmail dot com

floor(1.2)
3

floor(1.2)
4

floor(1.2)
5

floor(1.2)
6

echo 49 / 3;
>> 16.333333333333
1

17 năm trước

Marcm ¶

floor(1.2)
8

floor(1.2)
9

echo 49 / 3;
>> 16.333333333333
1

16 năm trước

9 tháng trước

(int)-1.2
1

(int)-1.2
2

(int)-1.2
3

echo 49 / 3;
>> 16.333333333333
1

James tại Bandit Dot Co.NZ ¶

Marcm ¶

(int)-1.2
5

(int)-1.2
6

(int)-1.2
7

(int)-1.2
8

16 năm trước

STM555 tại hotmail dot com

(int)-1.2
9

echo round(51.5); // Round the number, return 51.
echo floor(51.5); // Round down number, return 51.
echo ceil(51.3); // Round up number, return 52.
0

echo round(51.5); // Round the number, return 51.
echo floor(51.5); // Round down number, return 51.
echo ceil(51.3); // Round up number, return 52.
1

echo round(51.5); // Round the number, return 51.
echo floor(51.5); // Round down number, return 51.
echo ceil(51.3); // Round up number, return 52.
2

echo round(51.5); // Round the number, return 51.
echo floor(51.5); // Round down number, return 51.
echo ceil(51.3); // Round up number, return 52.
3

echo round(51.5); // Round the number, return 51.
echo floor(51.5); // Round down number, return 51.
echo ceil(51.3); // Round up number, return 52.
4

echo round(51.5); // Round the number, return 51.
echo floor(51.5); // Round down number, return 51.
echo ceil(51.3); // Round up number, return 52.
5

echo round(51.5); // Round the number, return 51.
echo floor(51.5); // Round down number, return 51.
echo ceil(51.3); // Round up number, return 52.
6

echo round(51.5); // Round the number, return 51.
echo floor(51.5); // Round down number, return 51.
echo ceil(51.3); // Round up number, return 52.
7

echo round(51.5); // Round the number, return 51.
echo floor(51.5); // Round down number, return 51.
echo ceil(51.3); // Round up number, return 52.
8

echo round(51.5); // Round the number, return 51.
echo floor(51.5); // Round down number, return 51.
echo ceil(51.3); // Round up number, return 52.
9

ceil()0

ceil()1

ceil()2

ceil()3

ceil()4

ceil()5

ceil()6

ceil()7

ceil()8

echo 49 / 3;
>> 16.333333333333
1

17 năm trước

Lio ¶

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
00

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
01

echo 49 / 3;
>> 16.333333333333
1

4 năm trước

Nospam tại Nospam Dot Com ¶

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
03

SGJ tại Tiến sĩ Dot Com ¶

19 năm trước

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
04

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
05

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
06

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
07

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
08

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
09

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
10

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
11

echo 49 / 3;
>> 16.333333333333
1

Tomislav tại Firmus-Grupa Dot HR ¶

9 năm trước

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
13

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
14

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
15

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
16

Thông tin tại Ensostudio Dot Ru ¶

9 tháng trước

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
17

James tại Bandit Dot Co.NZ ¶

13 năm trước

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
18

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
19

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
20

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
21

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
22

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
23

Thông tin tại Ensostudio Dot Ru ¶

9 tháng trước

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
24

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
25

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
26

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
27

echo 49 / 3;
>> 16.333333333333
1

James tại Bandit Dot Co.NZ ¶

9 tháng trước

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
29

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
30

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
31

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
32

echo 49 / 3;
>> 16.333333333333
1

James tại Bandit Dot Co.NZ ¶

Marcm ¶

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
34

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
35

echo 49 / 3;
>> 16.333333333333
1

16 năm trước

STM555 tại hotmail dot com

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
37

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
38

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
39

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
40

echo 49 / 3;
>> 16.333333333333
1

17 năm trước

Lio ¶

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
42

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
43

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
44

echo 49 / 3;
>> 16.333333333333
1

4 năm trước

13 năm trước

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
46

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
47

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
48

echo 49 / 3;
>> 16.333333333333
1

Thông tin tại Ensostudio Dot Ru ¶

13 năm trước

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
50

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
51

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
52

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
53

echo 49 / 3;
>> 16.333333333333
1

Thông tin tại Ensostudio Dot Ru ¶

STM555 tại hotmail dot com

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
55

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
56

echo 49 / 3;
>> 16.333333333333
1

17 năm trước

Lio ¶

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
58

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
59

echo 49 / 3;
>> 16.333333333333
1

4 năm trước

Lio ¶

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
61

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
62

echo 49 / 3;
>> 16.333333333333
1

4 năm trước

Marcm ¶

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
64

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
65

echo 49 / 3;
>> 16.333333333333
1

16 năm trước

Marcm ¶

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
67

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
68

echo 49 / 3;
>> 16.333333333333
1

16 năm trước

STM555 tại hotmail dot com

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
70

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
71

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
72

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
73

17 năm trước

13 năm trước

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
74

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
75

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
76

echo 49 / 3;
>> 16.333333333333
1

Lio ¶

Marcm ¶

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
78

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
79

echo 49 / 3;
>> 16.333333333333
1

16 năm trước

STM555 tại hotmail dot com

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
81

echo (int)(-3.75); //echoes "-3";
echo floor(-3.75); //echoes "-4";
82

echo 49 / 3;
>> 16.333333333333
1

Làm thế nào loại bỏ các số không từ số thập phân trong PHP?

$ num + 0 thực hiện thủ thuật. does the trick.

Làm thế nào tôi có thể có được 2 số thập phân trong PHP?

Hiển thị một số đến hai vị trí thập phân trong PHP..
Hàm sử dụng number_format () để hiển thị một số cho hai vị trí thập phân trong PHP ..
Sử dụng hàm vòng () để hiển thị một số đến hai số thập phân trong PHP ..
Sử dụng hàm Sprintf () để hiển thị một số đến hai vị trí thập phân trong PHP ..

Làm thế nào giá trị kiểm tra là thập phân hay không trong PHP?

Hàm is_numeric () trong ngôn ngữ lập trình PHP được sử dụng để đánh giá xem một giá trị là số hoặc chuỗi số.Các chuỗi số chứa bất kỳ số lượng chữ số nào, các dấu hiệu tùy chọn như + hoặc -, số thập phân tùy chọn và theo cấp số nhân tùy chọn.Do đó, +234.5E6 là một chuỗi số hợp lệ.is_numeric() function in the PHP programming language is used to evaluate whether a value is a number or numeric string. Numeric strings contain any number of digits, optional signs such as + or -, an optional decimal, and an optional exponential. Therefore, +234.5e6 is a valid numeric string.