2013-06-26 62 views
0

我的代碼有一些長期不變的數字,以避免錯誤,我想用千分宣佈
在Java 7中我可以這樣做:PHP數千個分隔符語法

int MyConst = 1_000_000; ///The token '_' (thousand separator) make it more clearance 

我如何能做到這一點的PHP?

+1

'$ MYCONST = 1000000;'? – Robert

+1

你不能在php中使用java7之類的分隔符。但你可以使用字符串與分隔符。但在使用它們之前,您必須將其轉換爲原始類型。例如MyConst =「1_000_000」; int MyIntConst = cast_to_int(MyConst);函數cast_to_int(str){return(int)str_replace(「_」,「」,str); }類似的東西 – kodmanyagha

回答

1

在PHP只需聲明$myVar = 1000000;

manual

的整數的大小是與平臺相關的,雖然約兩十億的最大值是通常的值(這是32位有符號)。 64位平臺的最大值通常約爲9E18。 PHP不支持無符號整數。整數大小可以使用常量PHP_INT_SIZE確定,最大值使用自PHP 4.4.0和PHP 5.0.5以來的常量PHP_INT_MAX。

1
在PHP我們做這樣

$input = 1000000; 
$output = number_format($input , 0 , '.' , '_'); 
echo $output; 

輸出

:1_000_000