Solidity: Underscores in number literals

Created on 9 Feb 2017  路  11Comments  路  Source: ethereum/solidity

It would be nice to support underscores in number literals to have easily readable numbers: 1_000_000.

Question:

  • should it allow multiple underscores next to each other 1__000_____000?
  • should it allow underscores at arbitrary places 1_0_00_000_0_000?
feature good first issue help wanted language design

All 11 comments

If we add such a thing, the only reasonable strategy would be to force all numbers except for the first into triples. What about fractional numbers?

Oh and to be honest, I find these underscores extremely ugly. What about 1 000 000?

What about fractional numbers?

I wouldn't allow fractional numbers if we're segmenting it with underscore.

Oh and to be honest, I find these underscores extremely ugly. What about 1 000 000?

I wasn't a big fan of the underscores, but it gained some following and is kind of understood what it means. Having whitespace could be confusing I think.

I don't think it makes sense to support this only for integers.

Here's Python's approach: https://www.python.org/dev/peps/pep-0515/

Has most of these questions covered.

looks good!

I'd take the design from existing languages. Python's one looks good.

Hello can I take up this issue?

Please ignore the first commit (https://github.com/Balajiganapathi/solidity/commit/7a449c472d2f6c39ff52c2a29abf2e55786d9d2e).

Have created a pull request with the second commit: https://github.com/ethereum/solidity/pull/3120.

Assigned to @Balajiganapathi

Note BTW that forcing triplets isn't super great, since in East Asia they separate zeros in quadruplets, and in India they do it in a third way, see https://en.wikipedia.org/wiki/Decimal_separator#Digit_grouping

@jtakalai Only hex numbers have strict validation. Decimal numbers don't have any such rules. So, any grouping rule should work.

Was this page helpful?
0 / 5 - 0 ratings