Rounding values up

Discuss OrbForms Designer and PocketC Architect

Postby kac on Fri Oct 18, 2002 12:25 pm

I have a variable that I am dividing by the value 50. If I enter an initial value of 25 into the variable and divide by 50 then assing the result to an (int) variable it results in a value of 0.

I need to be able to round this to 1 (or round up). The literal value is 5.0 e-1.

Can anyone help with a work around or the proper method for accomplishing this?
Posts: 18
Joined: Thu Oct 17, 2002 12:12 pm

Postby jims on Fri Oct 18, 2002 2:02 pm


It's probably a casting issue, by default if you divide an int with an int you get an int back. So you have to cast them to a float so you get a float back:

<pre id="code"><font face="courier" size="2" id="code">
int roundFloat2Int(float f) {
return (int)(f + 0.5);

handler mainForm.onopen() {
alert( roundFloat2Int((float)25 / (float)50) );
</font id="code"></pre id="code">

- jim
Posts: 34
Joined: Wed May 22, 2002 4:01 pm
Location: USA

Return to OrbForms Designer and PocketC Architect

Who is online

Users browsing this forum: No registered users and 1 guest