Write 42.42 - 42 in the PowerShell prompt
0.42 is returned
0,420000000000002 is returned
> $PSVersionTable
Name Value
---- -----
PSVersion 6.0.0-alpha
PSEdition Core
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 3.0.0.0
GitCommitId v6.0.0-alpha.9
CLRVersion
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
A possible mitigation could be as could be as it is done in C# Interactive to do "42.42m - 42m" to force the evalutation as Decimal.
Sorry, misread your request.
Workaround:
PS /home/steve/repos/PowerShell> [decimal]42.42 -42
0.42
The concern I have is this would be a breaking change
On the other hand think when you use it to do calculation on the shell? The user would expect the behavior of the calculator application and it gets an wrong result...
This obviously should not change the behavior in a script where 42.42 without indication of type should be always considered a double as is in C#.
@fanoI I agree that for interactive shell, I would prefer it to be a decimal for quick calculations. However, we try to keep the shell and scripting experience the same so there aren't any surprises switching from one to the other. Maybe for interactive we could do something with formatting so it looks like a decimal even though it's still a double.
I wouldn't change the default formatting because it is difficult to infer the expected precision people want to see, but it's relatively easy for folks to change that themselves.
We could add an m
suffix though, I think that's a good idea.
Isn't d
already defined for decimal literals?
@rkeithhill you're right
PS /home/steve> 42.42d - 42
0.42
I implemented it and I still can't remember that, d
will forever mean double to me.
We could still add m
to align with C# - I'm not sure if that's a good idea or not though.
LOL. I remembered that this feature was added but my first guess was m
as well. When that didn't work, I figured it might be d
(for decimal).
Some comments:
It is possible to add a sort of configuration so that Decimal is used by default when calculations whit fractional numbers are done in the shell?
Most helpful comment
Some comments: