REDUCING DECIMALS

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
LEGRAND
Coder
Posts: 49
Joined: Wed Jul 30, 2008 7:57 am

REDUCING DECIMALS

Post by LEGRAND »

Hello!
I have the following code line

PRINT "POINT1",LOI1,LAT1,DIST1
and the 4 variables are decimals with a lot of figures behind the comma.
Would like to limit them all to 6 decimal and thought to use PRINT USING "**.******" as follows

PRINT "POINT1",USING "**.*****";LOI1,LAT1,DIST1
as global instruction. It doesn't work. What should I write?
Thanks in advance
LEGRAND
Coder
Posts: 49
Joined: Wed Jul 30, 2008 7:57 am

REDUCING DECIMAL

Post by LEGRAND »

Rectification: OnLY THE 3 Last ariables are decimal numbers
Anonymous

Post by Anonymous »

This works but I think there is a better way.

Code: Select all


test = 10.034983409834324

print test

print mid$(ltrim$(str$(test)),1,9)
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Redefine the number as a SINGLE type variable. But QB automatically makes undefined numerical values single. I don't see a Double (#) suffix!

Test2! = test

PRINT USING is one command. The text template follows the command!

Code: Select all

PRINT USING "POINT1  ##.######, ##.######, ##.######"; LOI1; LAT1; DIST1 
Yes, you can include text in the template and the template can be a string variable set up for print using format before it is used.

Code: Select all

TMP$ = "POINT1  ##.######, ##.######, ##.######"
PRINT USING TMP$; LOI1; LAT1; DIST1 
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
LEGRAND
Coder
Posts: 49
Joined: Wed Jul 30, 2008 7:57 am

DECIMALS

Post by LEGRAND »

A very good help. Very happy.I thought to modify the variables but expected other possibilities.Many thanks
LEGRAND
Coder
Posts: 49
Joined: Wed Jul 30, 2008 7:57 am

DECIMALS

Post by LEGRAND »

Finally, I think I will have to redefine variables as long as I want to save in a file and cannot write something like
PRINT#1,PRINT USING "POINT1 **.******,**.******";LOI1;LAT1
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Try this

PRINT #1, USING TMP$; variable; list

Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Post Reply