itmuckel
itmuckel

Reputation: 1420

Java underscore equivalent in F#?

In Java it's possible to write 1_000_000 instead of 1000000 for better readability. Is there something equivalent in F#?

Upvotes: 2

Views: 103

Answers (1)

Tom
Tom

Reputation: 17577

This question was already asked on feature request page and the current status of this chanbge request is "planned" and "approved in principle".
So it may will be implemented in one of the next releases.

You can find more information about this request (like a summary about this feature, the motivation and suggested implementation details) on the github page for F#:

Summary

Allow underscores between any digits in numeric literals. This feature enables you, for example, to separate groups of digits in numeric literals, which can improve the readability of your code.

For instance, if your code contains numbers with many digits, you can use an underscore character to separate digits in groups of three, similar to how you would use a punctuation mark like a comma, or a space, as a separator.

Motivation

This is a popular feature in other languages. Some other languages with a similar feature:

  • Perl
  • Ruby
  • Java 7
  • C++11 (use single quote)

just to name a few...

Detailed design

You can place underscores only between digits. You cannot place underscores in the following places:

  • At the beginning or end of a number
  • Adjacent to a decimal point in a floating point literal
  • Prior to an F or L or other suffix
  • In positions where a string of digits is expected

Upvotes: 3

Related Questions