Ask Your Question

Standard use of underscores in numerals

asked 2019-12-01 21:47:05 +0200

dsejas gravatar image

Hello, Sage Community!

Since Python (and pretty soon Sage) supports underscores in numbers, like in 11_000_000, as an alternative to 11000000, I was wondering if Sage or Python have any requirement or standard style for their use.

Let me explain, in English, the 11000000 is written 11,000,000, so i could write it as 11_000_000 in Sage. However, in Spanish, we use a small space after every thee-digit group, except if the number is four digits long. Also, the integer and the decimal parts are treated separatedly. For example:

  • 4,321 is written as 4321, because it only has four digits, so I should write 4321 in Sage.
  • 54,321 is written as 54 321 (with a small space between 4 and 3), so I should write 54_321 in Sage.
  • 21, 1234 is written as 21,123 (because the integer part has only two digits, and the decimal part has only four), so I should write 21.1234 in Sage.

However, if I were to work with an international team of people, I suppose there should be some standard, because some will write 4_321 and 21.123_4, while I will write 4321 and 21.1234.

Is there any standard for using underscores in Sage numerals?

Thanks in advance for your answers!

32.12345 is written as

edit retag flag offensive close merge delete


It doesn't seem all that worth worrying about to me. How much is this actually used? I don't think having thousands separators are all that useful for numbers beyond a certain size anyways (I think above trillions it starts to get hard to comprehend even with them). But maybe I'm wrong.

Iguananaut gravatar imageIguananaut ( 2019-12-05 12:09:57 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-12-01 22:19:32 +0200

tmonteil gravatar image

updated 2019-12-24 00:29:22 +0200

Sage does not have any recommandation about that. I guess you should just follow Python's PEP 515/, which is not that strict either.

edit flag offensive delete link more



I would remove the word "precise" from your answer.

John Palmieri gravatar imageJohn Palmieri ( 2019-12-02 04:17:33 +0200 )edit

done :)

tmonteil gravatar imagetmonteil ( 2019-12-24 00:29:32 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-12-01 21:47:05 +0200

Seen: 255 times

Last updated: Dec 24 '19