×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

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.

# Real variables

## Real variables

(OP)
I have a real variable (i) that should be multiplied by a constant (3280) to give an integer value in n2.

example: 5.7 x 3280 = 18696

however, it stores it as a real number: 1.8696 Exp 4

So if I divide n2 by 10000 i get 1.8696 but how do I make this number an integer?

Thanx

~*Gwar3k1*~
"To the pressure, everything's just like: an illusion. I'll be losing you before long..."

### RE: Real variables

Look at the functions Int, Trunc, and Round

### RE: Real variables

(OP)
They only deal with 1 half of the number. Ive tried int, round, frac, trunc. And ive tried adding values together... but its still a real number =\

Any other ideas? If not ill split the number

~*Gwar3k1*~
"To the pressure, everything's just like: an illusion. I'll be losing you before long..."

### RE: Real variables

round and trunc return the type longint in turbo pascal 6.0. I doubt they're different in any other version. Int returns a real.
round and trunc obviously only deal with the whole number part of a real number. That's what they're for. If you want the fractional bit to x-decimal places then (1) remember that you can use ##.### etc. in print in order to print to x-decimal places, and (2) if you still need to do it, subtract from n it's whole number part, multiply by x, and round the result.

### RE: Real variables

(OP)
k thanx

~*Gwar3k1*~
"To the pressure, everything's just like: an illusion. I'll be losing you before long..."

### RE: Real variables

(OP)
i dont get it

i want 18696 not 1.869600000 E4 or 1 and 0.8696

~*Gwar3k1*~
"To the pressure, everything's just like: an illusion. I'll be losing you before long..."

### RE: Real variables

The results of the round and trunc functions are integers, so the expression write(round(1.869600000E4)) will put 18696 on screen.
Check if you don't accidentally put the result of round in a real variable! Round produces an integer, but if you store this integer in a real variable, it is converted to floating point again.

VAR r : real;
l : longint;

r:=1.869600000E4;
l:=round(r);
write(l);
=> 18696

Regards,
Bert Vingerhoets
vingerhoetsbert@hotmail.com
http://student.vub.ac.be/~bvingerh/
Don't worry what people think about you. They're too busy wondering what you think about them.

### RE: Real variables

(OP)
Yeah thats what i was doing (putting the value back in a real variable) Im an idiot. I came back to say I fixed it then saw your post =P

BTW whats wrong with the Tek Tips server? I keep getting 400s and 404s

~*Gwar3k1*~
"To the pressure, everything's just like: an illusion. I'll be losing you before long..."

### RE: Real variables

Note something that's being overlooked:  The variable *NEVER* contained "1.8696 Exp 4".  That's a text representation  of the binary data.  When you do a writeln(i) and i isn't exactly an integer you'll get that sort of stuff.  However, had you done writeln(i :1:0) you would have gotten the 18696 you wanted.  Specifying a too-short format is ok, it will use more digits left of the decimal if it needs to.

### RE: Real variables

(OP)
yeah =P was using that but it was still decimal ;)

~*Gwar3k1*~
"To the pressure, everything's just like: an illusion. I'll be losing you before long..."

#### 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!