[Php 4> = 4.2.0, Php 5, Php 7, Php 8]
floatval - nhận giá trị float của một biến — Get float value of a variable
Sự mô tả
floatval [hỗn hợp $value
]: float[mixed $value
]: float
Thông số
value
Có thể là bất kỳ loại vô hướng. FloatVal [] không nên được sử dụng trên các đối tượng, vì làm như vậy sẽ phát ra lỗi cấp E_NOTICE
và trả về 1.floatval[] should not be used on objects, as doing so will emit an E_NOTICE
level error and return 1.
Trả về giá trị
Giá trị phao của biến đã cho. Mảng trống Trả về 0, mảng không trống trở lại 1.
Các chuỗi rất có thể sẽ trả về 0 mặc dù điều này phụ thuộc vào các ký tự ngoài cùng bên trái của chuỗi. Các quy tắc phổ biến của việc đúc phao áp dụng.
Ví dụ
Ví dụ #1 floatVal [] ví dụfloatval[] Example
Ví dụ #2 FloatVal [] Ví dụ: Không phải số bên trái không phải là sốfloatval[] non-numeric leftmost characters Example
Xem thêm
- boolval [] - Nhận giá trị boolean của một biến
- intval [] - Nhận giá trị số nguyên của một biến
- strval [] - Nhận giá trị chuỗi của một biến
- setType [] - Đặt loại biến
- Loại tung hứng
Brewal Dot Renault tại Gmail Dot Com ¶ ¶
8 năm trước
This function takes the last comma or dot [if any] to make a clean float, ignoring thousand separator, currency or any other letter :
function tofloat[$num] {
$dotPos = strrpos[$num, '.'];
$commaPos = strrpos[$num, ','];
$sep = [[$dotPos > $commaPos] && $dotPos] ? $dotPos :
[[[$commaPos > $dotPos] && $commaPos] ? $commaPos : false];
if [!$sep] {
return floatval[preg_replace["/[^0-9]/", "", $num]];
}
return floatval[
preg_replace["/[^0-9]/", "", substr[$num, 0, $sep]] . '.' .
preg_replace["/[^0-9]/", "", substr[$num, $sep+1, strlen[$num]]]
];
}
$num = '1.999,369€';
var_dump[tofloat[$num]]; // float[1999.369]
$otherNum = '126,564,789.33 m²';
var_dump[tofloat[$otherNum]]; // float[126564789.33]
value
0
value
1Ẩn danh ¶ ¶
17 năm trước
value
2
value
3
value
1Alexey M ¶ ¶
6 năm trước
value
5
value
6
value
1Papapinguoin ¶ ¶
11 năm trước
value
8
value
9
E_NOTICE
0
value
1Ẩn danh khi bắt đầu chấm là ¶ ¶
18 năm trước
E_NOTICE
2
E_NOTICE
3
E_NOTICE
4
E_NOTICE
5radler63 tại hotmail dot com ¶
4 năm trước
E_NOTICE
6
E_NOTICE
7
E_NOTICE
8
value
1Chris tại Georgakopoulos Dot Com ¶ ¶
13 năm trước
0
1
value
1Steve tại Opilo Dot Net ¶
14 năm trước
3
4
value
1Secretr tại Nospam Dot E107 Dot org ¶ ¶
11 năm trước
6
7
8
9
0 value
1 ¶
14 năm trước
1
2
3
4
5Secretr tại Nospam Dot E107 Dot org ¶ ¶
17 năm trước
6
7
8
9Alexey M ¶ ¶
6 năm trước
This function takes the last comma or dot [if any] to make a clean float, ignoring thousand separator, currency or any other letter :
0
This function takes the last comma or dot [if any] to make a clean float, ignoring thousand separator, currency or any other letter :
1
value
1Papapinguoin ¶ ¶
4 năm trước
This function takes the last comma or dot [if any] to make a clean float, ignoring thousand separator, currency or any other letter :
3
This function takes the last comma or dot [if any] to make a clean float, ignoring thousand separator, currency or any other letter :
4
value
1Chris tại Georgakopoulos Dot Com ¶ ¶
13 năm trước
This function takes the last comma or dot [if any] to make a clean float, ignoring thousand separator, currency or any other letter :
6
This function takes the last comma or dot [if any] to make a clean float, ignoring thousand separator, currency or any other letter :
7
This function takes the last comma or dot [if any] to make a clean float, ignoring thousand separator, currency or any other letter :
8Steve tại Opilo Dot Net ¶
13 năm trước
This function takes the last comma or dot [if any] to make a clean float, ignoring thousand separator, currency or any other letter :
9
function tofloat[$num] {
0
$dotPos = strrpos[$num, '.'];
$commaPos = strrpos[$num, ','];
$sep = [[$dotPos > $commaPos] && $dotPos] ? $dotPos :
[[[$commaPos > $dotPos] && $commaPos] ? $commaPos : false];
function tofloat[$num] {
1
$dotPos = strrpos[$num, '.'];
$commaPos = strrpos[$num, ','];
$sep = [[$dotPos > $commaPos] && $dotPos] ? $dotPos :
[[[$commaPos > $dotPos] && $commaPos] ? $commaPos : false];
function tofloat[$num] {
2
$dotPos = strrpos[$num, '.'];
$commaPos = strrpos[$num, ','];
$sep = [[$dotPos > $commaPos] && $dotPos] ? $dotPos :
[[[$commaPos > $dotPos] && $commaPos] ? $commaPos : false];
value
1Steve tại Opilo Dot Net ¶
6 năm trước
function tofloat[$num] {
4
$dotPos = strrpos[$num, '.'];
$commaPos = strrpos[$num, ','];
$sep = [[$dotPos > $commaPos] && $dotPos] ? $dotPos :
[[[$commaPos > $dotPos] && $commaPos] ? $commaPos : false];
function tofloat[$num] {
5
$dotPos = strrpos[$num, '.'];
$commaPos = strrpos[$num, ','];
$sep = [[$dotPos > $commaPos] && $dotPos] ? $dotPos :
[[[$commaPos > $dotPos] && $commaPos] ? $commaPos : false];
function tofloat[$num] {
$dotPos = strrpos[$num, '.'];
$commaPos = strrpos[$num, ','];
$sep = [[$dotPos > $commaPos] && $dotPos] ? $dotPos :
[[[$commaPos > $dotPos] && $commaPos] ? $commaPos : false];
6Papapinguoin ¶ ¶
11 năm trước
function tofloat[$num] {
7
$dotPos = strrpos[$num, '.'];
$commaPos = strrpos[$num, ','];
$sep = [[$dotPos > $commaPos] && $dotPos] ? $dotPos :
[[[$commaPos > $dotPos] && $commaPos] ? $commaPos : false];
value
1 ¶
Ẩn danh khi bắt đầu chấm là ¶
function tofloat[$num] {
8
$dotPos = strrpos[$num, '.'];
$commaPos = strrpos[$num, ','];
$sep = [[$dotPos > $commaPos] && $dotPos] ? $dotPos :
[[[$commaPos > $dotPos] && $commaPos] ? $commaPos : false];
function tofloat[$num] {
9
$dotPos = strrpos[$num, '.'];
$commaPos = strrpos[$num, ','];
$sep = [[$dotPos > $commaPos] && $dotPos] ? $dotPos :
[[[$commaPos > $dotPos] && $commaPos] ? $commaPos : false];
value
118 năm trước ¶
Ẩn danh khi bắt đầu chấm là ¶
if [!$sep] {
1
return floatval[preg_replace["/[^0-9]/", "", $num]];
}
if [!$sep] {
2
return floatval[preg_replace["/[^0-9]/", "", $num]];
}
value
118 năm trước ¶
radler63 tại hotmail dot com
if [!$sep] {
4
return floatval[preg_replace["/[^0-9]/", "", $num]];
}
if [!$sep] {
5
return floatval[preg_replace["/[^0-9]/", "", $num]];
}
if [!$sep] {
6
return floatval[preg_replace["/[^0-9]/", "", $num]];
}
if [!$sep] {
7
return floatval[preg_replace["/[^0-9]/", "", $num]];
}
if [!$sep] {
8
return floatval[preg_replace["/[^0-9]/", "", $num]];
}
if [!$sep] {
9
return floatval[preg_replace["/[^0-9]/", "", $num]];
}
return floatval[
0
preg_replace["/[^0-9]/", "", substr[$num, 0, $sep]] . '.' .
preg_replace["/[^0-9]/", "", substr[$num, $sep+1, strlen[$num]]]
];
}
return floatval[
preg_replace["/[^0-9]/", "", substr[$num, 0, $sep]] . '.' .
preg_replace["/[^0-9]/", "", substr[$num, $sep+1, strlen[$num]]]
];
}
14 năm trước ¶
13 năm trước
return floatval[
2
preg_replace["/[^0-9]/", "", substr[$num, 0, $sep]] . '.' .
preg_replace["/[^0-9]/", "", substr[$num, $sep+1, strlen[$num]]]
];
}
return floatval[
3
preg_replace["/[^0-9]/", "", substr[$num, 0, $sep]] . '.' .
preg_replace["/[^0-9]/", "", substr[$num, $sep+1, strlen[$num]]]
];
}
value
1Steve tại Opilo Dot Net ¶
14 năm trước
return floatval[
5
preg_replace["/[^0-9]/", "", substr[$num, 0, $sep]] . '.' .
preg_replace["/[^0-9]/", "", substr[$num, $sep+1, strlen[$num]]]
];
}
return floatval[
6
preg_replace["/[^0-9]/", "", substr[$num, 0, $sep]] . '.' .
preg_replace["/[^0-9]/", "", substr[$num, $sep+1, strlen[$num]]]
];
}
value
1Secretr tại Nospam Dot E107 Dot org ¶ ¶
18 năm trước
return floatval[
8
preg_replace["/[^0-9]/", "", substr[$num, 0, $sep]] . '.' .
preg_replace["/[^0-9]/", "", substr[$num, $sep+1, strlen[$num]]]
];
}
return floatval[
9
preg_replace["/[^0-9]/", "", substr[$num, 0, $sep]] . '.' .
preg_replace["/[^0-9]/", "", substr[$num, $sep+1, strlen[$num]]]
];
}
$num = '1.999,369€';
0
var_dump[tofloat[$num]]; // float[1999.369]
$otherNum = '126,564,789.33 m²';
var_dump[tofloat[$otherNum]]; // float[126564789.33]
$num = '1.999,369€';
var_dump[tofloat[$num]]; // float[1999.369]
$otherNum = '126,564,789.33 m²';
var_dump[tofloat[$otherNum]]; // float[126564789.33]
1