ballerina-platform / ballerina-spec

Ballerina Language and Platform Specifications
Other
167 stars 54 forks source link

ToString operation on decimal is underspecified #1046

Open hasithaa opened 2 years ago

hasithaa commented 2 years ago

As of 2022R1, the spec says little about decimal toString representation and it doesn't mention when to use scientific notation, etc. https://github.com/ballerina-platform/ballerina-spec/blob/6eeb0610413fc0de4077114eb7afa45cfa410d9e/lang/spec.html#L3348-L3379

The jBallerina implementation follows Java conventions. i.e. Scientific notation etc.

jclark commented 2 years ago

One point is that the string format should preserve the precision. Generally, it shouldn't use exponential format except when necessary i.e. 1000 should be written as 1000 not 1.000e3.

jclark commented 2 years ago

There is the same problem with float. See #909. Float is actually more underdefined because float values do not have a precision.

jclark commented 2 years ago

@hasithaa More control over conversion of numbers to strings is issue #770.

jclark commented 2 years ago

One way for decimal to string to work is like this:

http://speleotrove.com/decimal/daconvs.html#reftostr

I don't fully understand the thinking behind that.