Here are two functions for converting a floating point number into a string representation using exponent notation. The functions allow specifying the number of significant digits to show.
I looked around for quite a while to find functions like this for saving floating point numbers to text files without using a binary representation of them. There are a few in the forum but the ones I am posting here take a slightly different approach and seem to be smaller and more straight forward.
It would be great if something similar could be implemented natively in PureBasic. They could also be added with additional formatting options to a sPrintF() implementation (hint

Code: Select all
Procedure.s strFE(x.f, dec.b = 6)
If x = 0: ProcedureReturn "0": EndIf
Protected e.l = (((PeekL(@x) >> 23) & %11111111) - 127) * Log10(2)
If dec < 0: dec = 0: EndIf
ProcedureReturn StrF(x / Pow(10, e), dec) + "e" +Str(e)
EndProcedure
Procedure.s strDE(x.d, dec.b = 6)
If x = 0: ProcedureReturn "0": EndIf
Protected e.q = (((PeekQ(@x) >> 52) & %11111111111) - 1023) * Log10(2)
If dec < 0: dec = 0: EndIf
ProcedureReturn StrD(x / Pow(10, e), dec) + "e" +Str(e)
EndProcedure
Debug strDE(-3.5e20)
Debug strDE(-3.5e-20)
Debug strFE(3.5e20)
Debug strFE(3.5e-20)