May 09, 2021, 02:28:02 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
   Home   Help Search Login Register  
Pages: [1]
Author Topic: Keeping the the zero at the end of decimals  (Read 3114 times)
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.
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.

Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
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

x = 1234.5
print using "$$####,.##";x

in the print using command:
 $$ means put a dollar sign in front
 # 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

if you made the code

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


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

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!