Numbers in Qbasic 
Author Message
 Numbers in Qbasic

Is there any way of putting extra zeros in front of a number in
Qbasic?  For example: the number 2.57664655445, is there a way to turn
it into 002.57664655445 without making a string?  It has to make the
integer part fully 3 digits, keeping the decimal part. So with 25.545,
it would turn into 025.545.  And any numbers that are already three
digits, they stay the same.  

Also, is there a way to get Qbasic to print two seperate variables
without a space between them?  When I put Print d; a the output would
be: d a. I want it to be da with no space.  D and A are numbers.

Please help me because I'm only starting to learn how to program.
Any help would be appreciated!

Peter Y.



Tue, 10 Nov 1998 03:00:00 GMT  
 Numbers in Qbasic

Quote:


>Subject: Numbers in Qbasic
>Date: Fri, 24 May 1996 01:47:15 GMT

To answer the second question first:

Quote:
>Also, is there a way to get Qbasic to print two seperate variables
>without a space between them?  When I put Print d; a the output would
>be: d a. I want it to be da with no space.  D and A are numbers.

QBasic puts a space in front of POSITIVE numbers, in negative numbers the
space is replaced by the minus sign.  You need to convert the number to
a string and then trim it  ie:

PRINT LTRIM$(VAL(d));LTRIM$(VAL(a))

Which leads us to the answer to the first question:

Quote:
>Is there any way of putting extra zeros in front of a number in
>Qbasic?  For example: the number 2.57664655445, is there a way to turn
>it into 002.57664655445 without making a string?  It has to make the
>integer part fully 3 digits, keeping the decimal part. So with 25.545,
>it would turn into 025.545.  And any numbers that are already three
>digits, they stay the same.  

Once more, you need to convert to a string and manipulate it appropriately

IntegersWanted=3
MyNum= 25.545

REM Get the Number as a string
Temp$ = LTRIM$(VAL(MyNum))

REM Find how big the integer part is
Integersize=INSTR(Temp$,".")

REM Make enough 0's
LeadingZero$=""
IF Integersize < Integerswanted THEN
    LeadingZero$ = STRING$("0",IntegersWanted - IntegerLength)
END IF

REM Put them together
MyNum$ = LeadingZero$ + Temp$

Cheers,
--
Disclaimer?? The opinions of the writer ARE the opinions of Lexacorp!!
----------------------------------------------------------------------
LEXACORP Pty Ltd, Brisbane, Qld Australia
Dataflex/MSAccess/Basic System Development



Tue, 10 Nov 1998 03:00:00 GMT  
 Numbers in Qbasic

: Is there any way of putting extra zeros in front of a number in
: Qbasic?  For example: the number 2.57664655445, is there a way to turn
: it into 002.57664655445 without making a string?  It has to make the
: integer part fully 3 digits, keeping the decimal part. So with 25.545,
: it would turn into 025.545.  And any numbers that are already three
: digits, they stay the same.  

I can't remember the exact syntax off-hand, but the PRINT USING command
should do it.  I think PRINT USING "###.###";25.545 would do what you
wanted.  (There may be another semicolon or comma or something in there,
too.)  There are several characters (in addition to "#") that give various
formats for numerical output.

: Also, is there a way to get Qbasic to print two seperate variables
: without a space between them?  When I put Print d; a the output would
: be: d a. I want it to be da with no space.  D and A are numbers.
[SNIP CLOSING FORMALITIES...]

I just thought of this, so I'm not sure if it would work or not (never
tried it).  Try PRINT D; CHR$(XXX); A (where XXX is the ASCII code for
RIGHT ARROW--either 28,29,30, or 31, I think).  That way it will print the
first value, back up a space, then print the second.  But this only works
if the space trails the first value, rather than preceeding the second (I
think it may be the latter, in which case you'd have to convert the number
to a string).  Or maybe PRINT USING would work again.  Hope this helps!

                                                =) jeff akins

--
| Jeff Akins  (a.k.a  mASch'T p'TeiGhTow)      //////|    "Necessity is  |

| Georgia Tech                              //  //==||    of invention." |
| Atlanta, GA                              //////   ||       ?  ?  ?     |



Tue, 10 Nov 1998 03:00:00 GMT  
 Numbers in Qbasic

Thanks!



Wed, 11 Nov 1998 03:00:00 GMT  
 Numbers in Qbasic

-> Is there any way of putting extra zeros in front of a number in
-> Qbasic?  For example: the number 2.57664655445, is there a way to
-> turn it into 002.57664655445 without making a string?  It has to make
-> the integer part fully 3 digits, keeping the decimal part. So with
-> 25.545, it would turn into 025.545.  And any numbers that are already
-> three digits, they stay the same.

It has to be done using string operators.

Try:

N$ = MID$(STR$(1000 + N),3)

It adds 1000 to your number (which is assumed to be less than 1000, for
it to have no more than three digits to the left of the point), turns it
into a string, then trims off the first two characters. These will be a
space and the "1" from the 1000. So what is left is your number preceded
by enough zeroes to make up the integer part to three digits.

Try it.

                              dow



Fri, 13 Nov 1998 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Random numbers in QBasic?

2. Reading the HD serial number from QBASIC

3. Help: How to get hard disk serial number using QBasic

4. Converting IEEE to MSBIN numbers in QBASIC 4.0

5. How to Round a Floating Point Number in Qbasic !!

6. qbasic screen mode - increase number of rows

7. qbasic syntax for hex numbers?

8. How does QBasic 4.5 generate random numbers?

9. QBasic Homepage With All Cool QBasic Goodies

10. QBASIC Challenge, QBASIC Webpage, Questions, Etc.

11. Qbasic 4.5 vs Qbasic 7.1PDS

12. Looking on information for Qbasic and Qbasic 4.5!

 

 
Powered by phpBB® Forum Software