home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / mac / programm / 19829 < prev    next >
Encoding:
Text File  |  1992-12-15  |  2.3 KB  |  51 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!spool.mu.edu!umn.edu!csus.edu!netcom.com!wysocki
  3. From: wysocki@netcom.com (Chris Wysocki)
  4. Subject: Re: International Number Formats
  5. Message-ID: <1992Dec15.050212.2405@netcom.com>
  6. Organization: Connectix Corporation, San Mateo, CA
  7. References: <4TS=Cj-@engin.umich.edu>
  8. Date: Tue, 15 Dec 1992 05:02:12 GMT
  9. Lines: 40
  10.  
  11. In article <4TS=Cj-@engin.umich.edu> Michael F. Kamprath <kamprath@space-grant.sprl.umich.edu> writes:
  12.  
  13. >I'm trying to decipher IM VI with respect to how to convert a floating point
  14. >number into a string to be displayed in the correct format (as set by the Nums
  15. >&Date control panel) and vice versa (that is, strings --> numbers).
  16.  
  17. Use the Script Manager routine Str2Format to convert a format string
  18. (such as "#,###,###;-#,###,###") to a canonical NumFormatString (which
  19. describes the format string in a script-independent manner), then use
  20. FormatX2Str and FormatStr2X to convert between 80-bit SANE extendeds
  21. and formatted strings.  You can obtain the necessary NumberParts table
  22. from the 'itl4' resource via:
  23.  
  24.     Handle      itl4H;
  25.     NumberParts parts;
  26.     
  27.     itl4H = IUGetIntl(4);
  28.     FailNILRes(itl4H);
  29.     parts = *(NumberParts *)(*itl4H + (**(Itl4Handle)itl4H).defPartsOffset);
  30.  
  31. The one trick is that you need to save the canonical NumFormatString
  32. returned by Str2Format in some way (e.g. in a resource), since
  33. Str2Format will interpret the format string differently depending on
  34. the current system environment (active script system, Numbers and
  35. Dates control panel settings, etc.)  To avoid this, write a throw-away
  36. program that calls Str2Format and saves the resulting NumFormatString
  37. in a resource.  Then, when you need to display a formatted number in
  38. your main program, get the saved NumFormatString resource, lock it
  39. down, and pass the dereferenced handle to FormatX2Str.  Complete
  40. details about Str2Format, FormatX2Str and FormatStr2X can be found in
  41. the Worldwide Guide to System Software stack, available on the
  42. developer CDs.
  43.  
  44. Chris.
  45. -- 
  46. ------------------------------------------------------------------------------
  47. Chris Wysocki                                     Internet: wysocki@netcom.com
  48. Software Engineer                                   America Online: AFA ChrisW
  49. Connectix Corporation                                   CompuServe: 72010,1140
  50.  
  51.