Dim e As String = Format (aDouble, "0.0###############")
My logic told me that this should be the exact oposite, any convertion should give the exact representation and FORMAT used to have a rounding option with less digits.
That’s all very well, but why should I need to? The default for double.ToText or str(double) should be to produce as many digits as are meaningful. Format should only be required for a specific rounding/layout.
[quote=435947:@Ivan Tellez]Well, that was correct, FORMAT did the trick.
Dim e As String = Format (aDouble, "0.0###############")
My logic told me that this should be the exact opposite, any conversion should give the exact representation and FORMAT used to have a rounding option with fewer digits.[/quote]
Well I agree with your logic - especially as the format string used above makes little sense when giving it a number like 542.405…
A Double by its very nature CANNOT give the exact representation of most fractional values. It’s up to you to control the level of rounding/truncation.
Well, that is a contradiction in your post. It is well known that doubles are not precise, but that is not the issue here.
Exactly, that is the way it should work, and that is the problem, Xojo making an arbitrary truncation by default instead of using all the meaningful digits.
[quote=451052:@Ivan Tellez]
Exactly, that is the way it should work, and that is the problem, Xojo making an arbitrary truncation by default instead of using all the meaningful digits.[/quote]
In the very first line: The significant figures (also known as the significant digits) of a number are digits that carry meaning contributing to its measurement resolution. This includes all digits
[quote=451060:@Norman Palardy]Leading an trailing zeroes are obvious #3 is important[/quote] #3 doesn’t apply in this situation, it’s a rule used in experimental measurements.
I would think once the value is stored as a double Xojo knows nothing about the significant digits of that value anyway, as mentioned by Norman before:
This is exactly what I would expect (as someone with little programming experience/knowledge).
That should be the default for str() and .ToText. If I want different, e.g., I’ve computed a probability, so it’ll be between 0.0 and 1.0, and I want to display 4 decimal places to the user in a table, I can use Format.