Hmm, using SimpleRoundTo instead of RoundTo does the trick, but why?
Could it be a wrong setting in my FPC 3.2.0 setup?
How can I prevent of getting 16 digits instead of the desired 2?
The number gets rounded to the nearest representable binary floating number.
The number gets rounded to the nearest representable binary floating number.
This sounds reasonable. However, the problem for me was that googling lead me to pages like this where they write RoundTo does the job in Delphi:
http://docwiki.embarcadero.com/Libraries/Sydney/en/System.Math.RoundTo
https://borland.public.delphi.vcl.components.using.narkive.com/KcnPqLk3/roundto-problem-with-delphi
https://stackoverflow.com/questions/5191235/why-is-the-result-of-roundto87-285-2-87-28
...
and thus I thought it will also do the job with FreePascal.
See this (http://pages.cs.wisc.edu/~rkennedy/exact-float?number=123.45) nifty site that shows the exact Single, Double and Extended presentation of that decimal number (though with Extended you might have luck more often than not, but that type is not available on all platforms).
Quite offtopic, but just to make sure that you are aware:
RoundTo (1.5,0); returns 2.
But
RoundTo (2.5,0); also returns 2.
Actually, I have no idea what these functions can be used for.
Quite offtopic, but just to make sure that you are aware:Round to just multiplies by the decimal factor, calls round and divides by the factor again, so basically RoundTo(val, digits) is basically just Round(val*10^digits)/10^digits.
RoundTo (1.5,0); returns 2.
But
RoundTo (2.5,0); also returns 2.
Actually, I have no idea what these functions can be used for.
Quite offtopic, but just to make sure that you are aware:
RoundTo (1.5,0); returns 2.
But
RoundTo (2.5,0); also returns 2.
Actually, I have no idea what these functions can be used for.
See this (http://pages.cs.wisc.edu/~rkennedy/exact-float?number=123.45) nifty site that shows the exact Single, Double and Extended presentation of that decimal number (though with Extended you might have luck more often than not, but that type is not available on all platforms).
Thanks. Unfortunately the link is dead but I understood now.