You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be helpful to have a more concise way to specify numbers of type decimal. JavaScript solved a similar issue with BigInts by using a postfix.
decimal("0.5") // current
0.5d // proposed
Use Case
We are currently not using decimals in some places it would make sense to, simply because decimal("0.5") is too long and would visually polute the codebase.
Reacted by Malo, Rafael Villar Burke (Pachi), David and Andreas Kröpelin
IMO this clashes with the existing use of a postfix for (length) units (pt, mm, in...) so I would prefer a more comprehensive extension of postfix: I propose to register either custom constructors which would not only allow 123.456d == decimal("123.456") as proposed here, but also custom units.
E.g. (defining custom postfix constructors using a leading underscore as a "placeholder", which is orthogonal to my custom constructors proposal and subject to bikeshedding)
To be clear: what I disagree with is to implement decimal literals in the compiler as #8288 does, what I propose instead is to allow registering custom postfix syntax sugar in user space.
This would not only be much more flexible and allow domain-specific postfix notations/units (including for STEM calculations 🥳), but I also dislike the d built-in/compiler postfix in particular because to me it evokes double or even day as much as decimal (I don't think that decimal and the d postfix are that common in scripting languages). A user-space definition of the d postfix for decimal would make the meaning explicit, which IMO is better in this case.
I generally agree that custom units are useful. However, i don't like the underscore-makes-things-special idea as e.g. tidy already uses underscores to mark private functions.
But back to this issue: In my opinion, if it is a primitive type, there should be compact compiler-defined syntax for it. Otherwise it feels cumbersome and I'll usually not use it. Even if there was the option to define custom syntax, there should be compiler syntax for it, so that I can look into any codebase and immediately see that it's a decimal.
I don't necessarily agree that the syntax would be inconsistent with units (a pt turns a double into length and d would turn a double into a decimal), but if that was the dealbreaker we could just prefix the number.
Regarding d looking like double, if most numbers don't have a pre-/postfix but then a user sees some with d, if think they would just look up what it means.
Ultimately I think decimal should be default floating point type instead of the binary one because of it is more intuitive but this is a different story :D
As a side note, C# und F# use m as a suffix to distinguish decimals from doubles. Considering there's already cm and mm though, this might be misinterpreted by readers to mean "meter"...
Activity
Lege19 commentedon May 14, 2026
I've implemented this, I'll open a PR when I've written some tests but it seems to work.
bastienvoirin commentedon May 27, 2026
IMO this clashes with the existing use of a postfix for (length) units (
pt,mm,in...) so I would prefer a more comprehensive extension of postfix: I propose to register either custom constructors which would not only allow123.456d == decimal("123.456")as proposed here, but also custom units.E.g. (defining custom postfix constructors using a leading underscore as a "placeholder", which is orthogonal to my custom constructors proposal and subject to bikeshedding)
It would be way cleaner and powerful with custom types obviously, and we could even imagine custom operations to make such units much more useful:
Example implementation
I'll try to open a proper issue but that was the gist in the meantime 😅Edit: #8585
bastienvoirin commentedon May 27, 2026
To be clear: what I disagree with is to implement
decimalliterals in the compiler as #8288 does, what I propose instead is to allow registering custom postfix syntax sugar in user space.This would not only be much more flexible and allow domain-specific postfix notations/units (including for STEM calculations 🥳), but I also dislike the
dbuilt-in/compiler postfix in particular because to me it evokesdoubleor evendayas much asdecimal(I don't think thatdecimaland thedpostfix are that common in scripting languages). A user-space definition of thedpostfix fordecimalwould make the meaning explicit, which IMO is better in this case.p-98 commentedon Jul 18, 2026
I generally agree that custom units are useful. However, i don't like the underscore-makes-things-special idea as e.g.
tidyalready uses underscores to mark private functions.But back to this issue: In my opinion, if it is a primitive type, there should be compact compiler-defined syntax for it. Otherwise it feels cumbersome and I'll usually not use it. Even if there was the option to define custom syntax, there should be compiler syntax for it, so that I can look into any codebase and immediately see that it's a decimal.
I don't necessarily agree that the syntax would be inconsistent with units (a
ptturns a double into length anddwould turn a double into a decimal), but if that was the dealbreaker we could just prefix the number.Regarding
dlooking likedouble, if most numbers don't have a pre-/postfix but then a user sees some withd, if think they would just look up what it means.Ultimately I think decimal should be default floating point type instead of the binary one because of it is more intuitive but this is a different story :D
linux-user36 commentedon Jul 19, 2026
As a side note, C# und F# use
mas a suffix to distinguish decimals from doubles. Considering there's alreadycmandmmthough, this might be misinterpreted by readers to mean "meter"...