Yeah, they have completely different datatypes which are also a lot slower than the usual floats, to fix that.Piero wrote: Wed Sep 13, 2023 2:29 pmYeah, I just had forgotten that it happens, being how floats/doubles are "stored"... anyway some languages "fix" that, or have math libraries to avoid the problemNicTheQuick wrote: Wed Sep 13, 2023 2:12 pm That's not shocking. That's normal in every programming language that uses floats. See https://en.wikipedia.org/wiki/Floating- ... y_problems
But you also have to look at the precision in general when converting floats to strings. Doubles have a precision of 15 decimal digits and floats have a precision of 7 decimal digits. With a log10() you can automatically choose the maximum precision before converting these numbers into a string:
Code: Select all
Procedure.s StrDmax(d.d)
Protected e.i = 15 - Round(Log10(d), #PB_Round_Down)
If e < 0
e = 0
EndIf
ProcedureReturn StrD(d, e)
EndProcedure
Procedure.s StrFmax(f.f)
Protected e.i = 7 - Round(Log10(f), #PB_Round_Down)
If e < 0
e = 0
EndIf
ProcedureReturn StrF(f, e)
EndProcedure
Debug StrDmax(10000000000000000)
Debug StrDmax(1.0)
Debug StrDmax(0.1)
Debug StrDmax(0.01)
Debug StrDmax(0.001)
Debug StrFmax(10000000000000000)
Debug StrFmax(1.0)
Debug StrFmax(0.1)
Debug StrFmax(0.01)
Debug StrFmax(0.001)
Define b.d = 0.4
Define c.d = 0.8
Debug StrDmax(b + c)