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

Ord and round functions

Status
Not open for further replies.

cnjihia

Technical User
Feb 18, 2003
4
KE
Hi
What are the C++ equivalents for the ord and round functions in delphi?What header file do I need to access them?
 
Not sure about round. There is ceil and floor which will give you the greatest integer less than and the smallest integer more than.

For ord, just cast it. For instance

int x = 48;
char c = (char) x;

or

char c = char(x);

To go in the opposite direction,

char c = 'A';
int x = (int) c;

or

int x = int(c);
 
Quick rounding routine that will fix the floating point flaw when trying to display a value on a form.

double To_Int(double Value)
{
double Lower, Upper, LDiff, UDiff, NewVal;
long int TempVal;
double ReturnVal;

NewVal = Value*10000;
Lower = floor(NewVal);
Upper = ceil(NewVal);
LDiff = NewVal - Lower;
UDiff = Upper - NewVal;
if (LDiff < UDiff)
TempVal = (long int) Lower;
else
TempVal = (long int) Upper;

ReturnVal = (double) TempVal/10000;

return ReturnVal; // Extend 4 decimal places
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top