home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sys / mac / programm / 18740 < prev    next >
Encoding:
Internet Message Format  |  1992-11-20  |  1.5 KB

  1. Path: sparky!uunet!ogicse!reed!bowman
  2. From: bowman@reed.edu (BoBoRamDos)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: Re: Floating Point to String Conversion
  5. Keywords: International, Worldwide
  6. Message-ID: <1992Nov21.001658.22424@reed.edu>
  7. Date: 21 Nov 92 00:16:58 GMT
  8. Article-I.D.: reed.1992Nov21.001658.22424
  9. References: <357@snll-arpagw.llnl.gov>
  10. Organization: Reed College, Portland, OR
  11. Lines: 36
  12.  
  13. In article <357@snll-arpagw.llnl.gov> ejfried@snll-arpagw.llnl.gov (friedman_hil
  14. l ernest j) writes:
  15. >Question: It seems like it is now possible to do floating point number ->
  16. >text string conversion using system software instead of sprintf.
  17.  
  18. Here's what I use:
  19.  
  20. void ExtendToText(Str255 *outch,extended realNumber)
  21. {
  22.         short index=0;
  23.         decform theForm;
  24.         decimal theDecimal;
  25.  
  26.         theForm.digits = fFieldLength;
  27.  
  28.         switch (fOutputType) {
  29.                 case fixed:
  30.                         theForm.style = FIXEDDECIMAL;
  31.                         break;
  32.                 case scientific:
  33.                         theForm.style = FLOATDECIMAL;
  34.                         theForm.digits++;
  35.                 // FLOATDECIMAL sucks 1 digit to the left of the dec point
  36.                         break;
  37.         }
  38.  
  39.  
  40.         num2dec(theForm,realNumber,theDecimal);
  41.         dec2str(theForm,theDecimal,(char *) outch);
  42.         c2pstr((char *) outch);
  43. }
  44.  
  45. cheers,
  46. bobo              In seeking the unattainable,
  47. bowman@reed.edu            simplicity only gets in the way.
  48. A geek, by any other name...
  49.