Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Keeping the the zero at the end of decimals
#1
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
Reply
#2
"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.
Reply
#3
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 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

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
WHILE RPG$ <> "complete" : make up silly excuses :WEND
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)