Printing result in exponential form

General discussion for topics related to the FreeBASIC project or its community.
Post Reply
niels olsen
Posts: 29
Joined: May 28, 2006 18:32
Location: denmark

Printing result in exponential form

Post by niels olsen »

I hold freebasic V 0.4.6, 19 feb 2006.
In a version elder than this it was possible to print result in exponential form, but somebody has been too smart and has removed
this ability from the program. WHY??
At that time the programming could look like: LPRINT "##.###^^^^"; x, and the result looked something like: 1.234E+03.
Do you have an easy solution. Do suggest up-dating. That I am not doing, as freebasic is not backward compatible, because
it would means I had to re-write more than 150 programs. A solution must not fort new program!
Yours sincerely
Niels Olsen
Imortis
Moderator
Posts: 1924
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Printing result in exponential form

Post by Imortis »

0.4.6 is not a freeBasic compiler version. It is a FBIDE version.

Also, I don't think that has been removed from the compiler.

https://www.freebasic.net/wiki/KeyPgLprint

It looks like you need to use "Using" with LPRINT to get that.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Printing result in exponential form

Post by dodicat »

Perhaps something like

Code: Select all

#lang "fblite"
#include "crt.bi"

dim as zstring * 50 s
for n as long=1 to 20
    sprintf(@s,"%e",rnd*1000-rnd*1000)
    lprint s 
next
print "done, press a key to print"
sleep
     
     
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Printing result in exponential form

Post by caseih »

niels olsen wrote: Mar 24, 2023 16:48At that time the programming could look like: LPRINT "##.###^^^^"; x, and the result looked something like: 1.234E+03.
No not quite. You forgot the "USING" keyword there. Without the USING keyword you will not get exponent number display with QB or FB.

Exponential number formatting is certainly still in FB, and it is in all dialects. It's done the same way it has always been done with "LPRINT USING" or "PRINT USING."

https://www.freebasic.net/wiki/KeyPgPrintusing

Also the FBLite dialect that you are likely using is still supported in the latest version, so your old code should compile and run just fine if you make sure to tell the compiler to use fblite. QB dialect is also still supported.
Post Reply