You’ve probably encountered situations where you need to write out a large number, and the longer it gets, the harder it is to tell how many digits it actually has. Is 130000000 equal to 13 million, 130 million, or 1.3 billion? At first glance, it’s a mess.
$number = 130000000 // This number is 😐?
One alternative is to use exponential notation, which makes the magnitude clear:
$number = 130e6 // immediately obvious: 130 million 🤘
But for numbers like 133456115, writing it as 133.456115e6 starts to feel counterproductive.
Starting with PHP 7.4, there’s a handy new syntax: the numeric literal separator. You can sprinkle underscores into your numbers to improve readability, just like you would in a miliseconds or any other long number that you want to ready clearly:
$number = 130_000_000; // 🤩 WOW, that’s clearly 130 million!
The underscores don’t change the value or the type:
var_dump(130_000_000 === 130000000); // true (integer === integer) var_dump(130_000_000.000 === 130000000); // false (float !== integer)
See the RFC for more details:
PHP RFC
PS: JavaScript supports a similar feature!
Top comments (0)