Good catch! Negative notation isn't something which we see very often, and the glitch here is mine, instead of QB64s.
1e-8 -- this says we have 1, then shift it to the right 8 places, giving us 0.00000001...
Unfortunately, I simply interpeted it as "add 8 zeros in front", giving us 0.000000001... This is an extra 0, which we don't actually have!
(In my defense, 1e8 is as simple as "add 8 zeros behind", giving us 100000000... Unfortunately, the same logic doesn't quite hold true, in this case, for negative exponents.)
The change is extremely simple to implement:
Down on line 52, change the following: FOR i = 1 TO -r&&
To: FOR i = 1 TO (-r&& - 1)
That's it! One little alteration and it works as it should. This glitch is entirely from my own flawed logic with notations, and has nothing at all to do with QB64.
1e-1 = 0.1, not .01, as I was thinking it did.
Fixed code is below, for those who simply don't want to alter it themselves:
_TITLE "N2S$ testing for a scientific notation remover" 'b+ 2020-09-04
' looks pretty good except for one little bug
IF 1 THEN ' < 0 to skip section, 1 to run section n = 1 ' has an odd bug jump -7 to -8 moves right 1 extra 0
IF 0 THEN ' < 0 to skip section, 1 to run section n## = 1 ' but this OK too
'n## = 27.0123456789 'OK
'n## = (1 / 3) 'OK
FUNCTION N2S$
(EXP$
) 'remove scientific Notation to String (~40 LOC) 'SMcNeill Jan 7, 2020 ref: https://www.qb64.org/forum/index.php?topic=1555.msg112989#msg112989
'Last Function in code marked Best Answer (removed debug comments and blank lines added these 2 lines.)
IF check1
< 1 OR check1
> 1 THEN N2S
= EXP$:
EXIT SUB 'If no scientic notation is found, or if we find more than 1 type, it's not SN! SELECT CASE l
'l now tells us where the SN starts at. l$
= LEFT$(t$
, l
- 1) 'The left of the SN r$
= MID$(t$
, l
+ 1): r&&
= VAL(r$
) 'The right of the SN, turned into a workable long IF INSTR(l$
, ".") THEN 'Location of the decimal, if any r&& = r&& + 1
CASE 0 'what the heck? We solved it already? 'l$ = l$
l$ = "0" + l$
l$ = "0." + l$
l$ = l$ + "0"
l$ = l$
IF sign$
= "" THEN sign$
= " " N2S$ = sign$ + l$