Path: utzoo!attcan!uunet!samsung!usc!ucsd!hub.ucsb.edu!castor!stoms From: stoms@castor.ncgia.ucsb.edu (David Stoms) Newsgroups: comp.sys.mac.programmer Subject: Re: Floating Point #'s as Strings in Dialogs using Think C 3.0 Keywords: Getting garbage in TextItems...how come? Message-ID: <5772@hub.ucsb.edu> Date: 11 Jun 90 18:16:08 GMT References: <25837@netnews.upenn.edu> Sender: news@hub.ucsb.edu Reply-To: stoms@castor.ncgia.ucsb.edu () Distribution: na Organization: U. C. Santa Barbara, Geography Department Lines: 64 In article <25837@netnews.upenn.edu> isler@grad1.cis.upenn.edu () writes: >I am writing a program in Think C 3.0 in which I would like to convert >floating point numbers to strings and place them in EditText items in >a dialog box. >The result is that garbage is printed in the dialog instead of the >converted string. The above conversion method works fine when I am >displaying floats as strings in windows, but it does not work here. typedef char[32] FStr; Double2String(double num, int digits, FStr string) { char bcdNum[12]; int i, j; char c; if (!string) Debugger(); /* I believe SANE does this too */ asm { fmove.x num,fp0 fmove.p fp0,bcdNum{#17} } j = 1; c = bcdNum[3]; if (bcdNum[0] & 0x8000) string[j++] = '-'; string[j++] = (c & 0xf) + '0'; string[j++] = '.'; digits = 16 - digits; if (nbtwn(digits, 0, 16)) Debugger(); for (i=4; i <= 11 - (digits>>1); i++) { c = bcdNum[i]; string[j++] = (c>>4 & 0xf) + '0'; string[j++] = (c & 0xf) + '0'; } j -= digits % 2; /* while (string[j-1] == '0') j--; */ if (string[j-1] == '.') j--; string[j++] = 'e'; string[j++] = (bcdNum[0] & 0x4000) ? '-' : '+'; i = false; if ( (bcdNum[0] & 0xf) != 0 ) { string[j++] = (bcdNum[0] & 0xf) + '0'; i = true; /* significant digit */ } if ( i || (bcdNum[1]>>4 & 0xf) != 0) { string[j++] = (bcdNum[1]>>4 & 0xf) + '0'; i = true; } if ( !i && bcdNum[1] & 0xf == 0) j -= 4; else string[j++] = (bcdNum[1] & 0xf) + '0'; string[0] = j-1; } Josh.