Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Real variables

Status
Not open for further replies.

gwar2k1

Programmer
Apr 17, 2003
387
GB
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..."
 
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..."
 
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.
 
k thanx

~*Gwar3k1*~
"To the pressure, everything's just like: an illusion. I'll be losing you before long..."
 
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..."
 
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.
Code:
VAR r : real;
    l : longint;

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

Regards,
Bert Vingerhoets
vingerhoetsbert@hotmail.com
Don't worry what people think about you. They're too busy wondering what you think about them.
 
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..."
 
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.
 
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..."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top