Qbasicnews.com
March 31, 2020, 07:15:28 AM
 Pages: [1]
 Author Topic: Keeping the the zero at the end of decimals  (Read 2670 times)
gummo
New Member

Posts: 3

 « on: May 27, 2008, 01:08:30 AM »

Sorry if this sounds stupid, but I haven't used Quick Basic in years, and I'm attempting to make an economic sim game. QB drops the zeros that I use in decimal numbers,  and I was wondering if there was a way around that, that wasn't too cumbersome. Basically what I'm trying to do is to manipulate the price of goods and the player's income. Also, if anyone is aware of tutorials in making this sort of game I'd be very grateful. Thanks much.
-s.davis
 Logged
Ralph
Ancient Guru

Posts: 544

 « Reply #1 on: May 27, 2008, 02:27:10 PM »

"True" numbers don't have leading  or trailing zeroes.  So, if you want to use, say,
x = 45.60, you cannot use a "number"; you have to use strings.  So, you would code the above as x\$ = "45.60".

If you want to use numbers, and your results are, say, x = 45.6, you can print this out as 45.60 by two methods: either you convert it to a string with a trailing zero, say by the code,  x\$ = STR\$(x) + "0", which would be too straneous and very indirct, or, best by a long shot, you can use the QB PRINT USING statement.  Read up on it in the QuickBASIC 4.5 IDE by clicking on Help, then Index, then P, then on the PRINT USING statement.

Once you master that bit of code, practice it and, if you still have a problem, post back, showing the respective code, stating your expected results, and explaining any problem you are having.
 Logged

Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
LPG
Member

Posts: 61

semper ubi sub ubi (always wear under wear)

 « Reply #2 on: May 28, 2008, 01:59:10 AM »

The following code uses print using to print 1234.5 as \$1,234.50

Code:
cls
x = 1234.5
print using "\$\$####,.##";x

in the print using command:
# means print a digit so four means print four digits
, before the dot means put a comma every 3 spaces
. means put the decimal point here

Code:
cls
x = 1234.5
print using "\$\$########,.##

it would output the same but would also work if x = 12345678.5 where the first example wouldn't.

hope that helped

LPG
 Logged

WHILE RPG\$ <> "complete" : make up silly excuses :WEND
 Pages: [1]