_TITLE "N2S$ testing for a scientific notation remover" 'b+ 2020-09-04 ' looks pretty good except for one little bug
' 2020-09-06 fixed ? see comment line with this date
IF 0 THEN ' < 0 to skip section, 1 to run section 2020-09-06 this section looks good! n = 1 ' has an odd bug jump -7 to -8 moves right 1 extra 0 OK beautiful 2020-09-06!
'n = 0.003 ' 2020-09-06 this looks fine too
'n = 1000 / 3 '2020-09-06 fine!
IF 1 THEN ' < 0 to skip section, 1 to run section n## = 1.0 ' but this OK too (when n=1 wasn't working) 2020-09-06 Now this is wrong!!!
n## = 1000 / 3 'OK and this
n## = .003 'OK and this
'PRINT i, STR$(n## * 10 ^ -i), N2S$(STR$(n## * 10 ^ -i))
FUNCTION N2S$
(EXP$
) 'remove scientific Notation to String (~43 LOC) DIM t$
, sign$
, L$
, R$
, r&&
'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$
= _TRIM$(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$
FOR i
= 1 TO (-r&&
- 1) 'fix SMcNeill 2020-09-06 L$ = "0" + L$
L$ = "." + L$ ' 2020-09-06 removed 0 of "0." + L$ to keep consistent with other returns
L$ = L$ + "0"
L$ = L$
N2S$ = sign$ + L$