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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying whole number of real variable

Status
Not open for further replies.

wcccprogramming

Instructor
Nov 4, 2003
2
US
How do I display the whole number of a real variable if the number does not have any decimal places. I need to display the number with decimal places if it has any.

Ex.

3.00 as 3
3.45 as 3.45
 
This is actually one of the rare cases where I'd (1) use str to convert the decimal to a string with the largest number of decimal places I will ever need, then (2) check it really is a decimal by making sure pos('.', mystring) is greater than zero (and remember that not all nations use '.' as a decimal). and then (3) chew off zeroes from the right hand side until I meet a decimal point (which should also be chewed) or a non-zero digit.

But there's probably a simpler way.
 
I think that would indeed be the best way to do it; One remark though, I think Borland Pascal always uses a dot as decimal separator, regardless of any system configuration.


Regards,
Bert Vingerhoets
vingerhoetsbert@hotmail.com
Don't worry what people think about you. They're too busy wondering what you think about them.
 
... or you can use the Int() function to determine how to display the Real:

Code:
Function Whole(Source : Real) : Boolean;
Begin
  If (Int(Source) <> Source) then
    Whole := False
  Else
    Whole := True;
End;

Good Luck §;O)


Jakob
 
Thank you for you help. I will try and use the string solution tonight. Your help is appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top