0

我的代码有一些很长的常数,为了避免错误我想用千位分隔符声明
在java 7中我可以这样做:

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

我怎么能在 PHP 中做到这一点?

4

3 回答 3

1

PHP 不提供这样的功能。见:http ://www.php.net/manual/en/language.types.integer.php

您可以使用科学记数法来表示大数字:http ://www.php.net/manual/en/language.types.float.php但话又说回来,您的整数实际上是浮点数,您可能必须添加类型转换.

于 2013-06-26T07:50:51.757 回答
1

在php中,您只需声明$myVar = 1000000;

手册

整数的大小取决于平台,尽管通常值约为 20 亿的最大值(即 32 位有符号)。64 位平台的最大值通常约为 9E18。PHP 不支持无符号整数。自 PHP 4.4.0 和 PHP 5.0.5 起,可以使用常量 PHP_INT_SIZE 确定整数大小,使用常量 PHP_INT_MAX 确定最大值。

于 2013-06-26T07:51:53.563 回答
1

在php中我们这样做

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

输出:1_000_000

于 2013-06-26T07:52:37.137 回答