Qbasicnews.com

Full Version: newbie here :( and i dont like decimals
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
hey im and im just learning this and i have a program that has to do with money and i have it so sometimes the cost of something comes out $9.352214 instead of $9.35 how do i round off the to the 2nd decimal so it really looks like money ....and also dose anyone know of a site that has a list of QB funtions and what they do
Print Using.
? ... lol im really really new so say the price came out to 22.1687 ...........so price = 22.1687

how do i convert it to 22.17
like show me an example ...plz
Example:[syntax="qbasic"]a# = 123.456789#
PRINT "a# is"; a#
PRINT "a# rounded to the nearest thousandth is ###.###"; a#[/syntax]
Example:

[syntax="qbasic"]'Format and print numeric data.
CLS ' Clear screen
PRINT USING "##.##"; .78
PRINT USING "###.##"; 987.654
PRINT USING "##.## "; 10.2, 5.3, 66.789, .234
PRINT USING "+##.## "; -68.95, 2.4, 55.6, -.9
PRINT USING "##.##- "; -68.95, 22.449, -7.01
PRINT USING "**#.# "; 12.39, -0.9, 765.1
PRINT USING "$$###.##"; 456.78
PRINT USING "**$##.##"; 2.34
PRINT USING "####,.##"; 1234.5
PRINT USING "##.##^^^^"; 234.56
PRINT USING ".####^^^^-"; -888888
PRINT USING "+.##^^^^"; 123
PRINT USING "+.##^^^^^"; 123
PRINT USING "_!##.##_!"; 12.34
PRINT USING "##.##"; 111.22
PRINT USING ".##"; .999[/syntax]

Code:
Sample Output

0.78
987.65
10.20    5.30   66.79    0.23
-68.95    +2.40   +55.60    -0.90
68.95-   22.45     7.01-
*12.4   *-0.9   765.1
$456.78
***$2.34
1,234.50
2.35E+02
.8889E+06-
+.12E+03
+.12E+003
!12.34!
%111.22
%1.00

have a look here for more info:
http://qbasicnews.com/qboho/qckadvr@l816d.shtml

Oracle: why isnt 0.999 being highlighted?
Quote:? ... lol im really really new so say the price came out to 22.1687 ...........so price = 22.1687

how do i convert it to 22.17
like show me an example ...plz

Homework?

Code:
prize! = 22.1687
prize% = prize! * 100
prize! = prize% / 100

Print Prize!

Multiply by 100, round it, divide by 100.
thats gay y dose it put % infront of it .......the program im makeing has it so some one would input a money vaule then it gets added and subtraced and mutiplyed by stuff so by the time its done it could be $67.998888883 and all i want to do is have it round off the the hundth place so it looks like money im useing
Code:
PRINT USING "##.##"; money
so why dose it work and round off to the hundrth but after that put a % sine infront of it i dont want the % how do i get ride of %

by the way thanks for the help everyone
You don't put anything in front of it, you put a type after it.

! = single precission floating point
# = double precission floating point
% = signed integer, range -32768 to 32767
& = signed long integer, range -2147483648 to 2147483647


integers cannot hold decimals at all.

If you have:
0.123456

And multiply it by 100, you get:
12.3456

right.

If you store that number as an integer, you get 12. (No decimals.)

a% = 12.3456

Just means that the integer a, will hold the value 12, as it cannot hold any decimals, because it's an integer.

Now you have 12

But you want: 0.12.

Just do:
Print 12/100

Or:
Print a% / 100



And pay attention in class.




If you don't want the %, don't use it. Just use Print Using, which only shows a different value, but doesent really change anything on the variable.



One could even write a function that convertad a decimal containing number into string, and then only got X number of decimal places, and turned it back into a numerical value.



Code:
Input "Prize:"; prize!

'One way of doing it:
Print "The prize with 2 decimals:"; INT(prize!*100) / 100

'Other way of doing it:
Print "The prize with 2 decimals:";
Print Using "###.##"; prize!



And yes, at this moment, I am gay. So what.
The percent sign zhahaman is referring to is the overflow character that QB prints when your number is too big for the field. To fix this, just add more #s:

PRINT USING "####.##"; money
Oh.. Sorry..

I missunderstood..


Dissregard my last post, though it's a good solution, it's prolly not what you need.
Pages: 1 2