INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Remember Me

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Just copy and paste the

# rounding numbers

Share

## rounding numbers

(OP)
i was wondering if someone could tell me how to round numbers with decimals to a whole number

### RE: rounding numbers

Look in the help files for INT() function.

### RE: rounding numbers

INT() always rounds the number down.
If you want it to round as a normal human would round such as 4.5 to 5 instead of what Qbasic would do and round 4.5 to 4 then just add .5

a=4.5

If you wanted to round like a normal human then you would
a=a+.5
PRINT INT(a)

Or just round like the computer would
PRINT INT(a)

### RE: rounding numbers

a = 4.55
IF a > INT(a) + .5 THEN
a = INT(a) + 1
ELSE
a = INT(a)
END IF
PRINT a

### RE: rounding numbers

Since QB4.5 doesnt have a currency floating point type here
is what I did.

DIM Dollar as long
DIM Cents as integer
DIM Amount as double

input amount
Dollar=Amount
Cents=(Amount-Dollar)*100
print Dollar;".";Cents
print using "##,###.##";Dollar+cents/100

this can also be stored in 5 bytes using mkl$and chr$
amt$=msk$(Dollar)+chr$(cents) one Caveat: you need to check for negative cents before using chr$(cents)

If Cents<0 then Dollar=Dollar-1:Cents=Cents+100

then to get them back
Dollar=CVL(mid$(amt$,1,4))
Cents=asc(mid$(amt$,5,1))

### RE: rounding numbers

To round like a human, use the CINT() function.  On extremely large numbers, using CINT() will give you an error.  That is why most people use the INT() function whenever possible.

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!