[comp.sys.mac.programmer] Changing floats to ints

eck@eniac.seas.upenn.edu (Hangnail Whipperwill) (10/30/90)

   I am trying to discover a way to convert my float R to an integer so that
NumToString will work properly.  Any help is appreciated, but if you don't
read this before the morning of October 30th, please do not reply...that's my
deadline!  Anyway, thanks in advance...source code follows.

Brian
eck@eniac.seas.upenn.edu



#include <math.h>
#include <stdio.h>

#define pi 3.141579
#define BASE_RES_ID		400
#define NIL_POINTER		0L
#define MOVE_TO_FRONT		-1L
#define REMOVE_ALL_EVENTS	0

WindowPtr	gPictureWindow;

float	R = 0;				/* lens radius */
float	n = 0;				/* index of refraction */
float	f = 0;				/* focal length of lenses */
float	s1 = 2;				/* distance from object to lens */
float	s2;				/* distance from lens to image */
int	x;				/* counter */
char	valstring[256];			/* anonymous string */


/*** Main ***/

main()
{
	ToolBoxInit();
	WindowInit(BASE_RES_ID);
	MainLoop();
	while(!Button());
}


/*** ToolBoxInit ***/

ToolBoxInit()
{
	InitGraf(&thePort);
	InitFonts();
	FlushEvents(everyEvent,REMOVE_ALL_EVENTS);
	InitWindows();
	InitMenus();
	TEInit();
	InitDialogs(NIL_POINTER);
	InitCursor();
}


/*** WindowInit ***/

WindowInit(res_id)
int	res_id;
{
	gPictureWindow = GetNewWindow(res_id, NIL_POINTER, MOVE_TO_FRONT);
	ShowWindow(gPictureWindow);
	SetPort(gPictureWindow);
	MoveTo(50,15);
	DrawChar(82);
	DrawChar(58);
}


/*** MainLoop ***/

MainLoop()
{

	/* Method one */
	
	x = 2;
	for (R = 0.05; R < 0.1; R += (0.01))
		{
		x++;
		for (n = 1; n < 2.4; n += (0.2))
			MoveTo(50,(x*15));
			NumToString((long) R,valstring);
			DrawString(valstring);
		}
}

Chris.Gehlker@p12.f56.n114.z1.fidonet.org (Chris Gehlker) (11/20/90)

eck@eniac.seas.upenn.edu (Hangnail Whipperwill) writes:

>    I am trying to discover a way to convert my float R to an integer so that
> NumToString will work properly.

Forget NumToString(). Just use Num2Str() which will convert your
float directly.

--  
Uucp: ...{gatech,ames,rutgers}!ncar!asuvax!stjhmc!56.12!Chris.Gehlker
Internet: Chris.Gehlker@p12.f56.n114.z1.fidonet.org