home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / i18nv102.zip / SAMPLE / MONEY / MONEY.C < prev    next >
C/C++ Source or Header  |  1995-08-28  |  3KB  |  64 lines

  1. /*****************************************************************************/
  2. /***     Include files                                                     ***/
  3. /*****************************************************************************/
  4.  
  5. #include <stdio.h>                      /* Standard IO functions.            */
  6.  
  7. #include <wchar.h>                      /* XPG/4 library.                    */
  8. #include <locale.h>                     /* Locale definitions.               */
  9.  
  10. /*****************************************************************************/
  11. /***     Global variables                                                  ***/
  12. /*****************************************************************************/
  13.  
  14. char *locale;                           /* Name of locale string.            */
  15.  
  16. /*****************************************************************************/
  17. /***     Sample date and time conversion                                   ***/
  18. /*****************************************************************************/
  19.  
  20. void monetary_functs(void)
  21. {
  22.   char out_str[255];                    /* Output string for conversions.    */
  23.   double num = 0.0;                     /* Input number for conversions.     */
  24.  
  25.                                         /* Print a header.                   */
  26.   printf("\nLocale for monetary: %s\n", locale);
  27.  
  28.                                         /* Set number to convert.            */
  29.                                         /* Convert without currency symbol.  */
  30.                                         /* Print output results.             */
  31.   num = 12345.6789;
  32.   strfmon(out_str, sizeof(out_str), "Symbol-less format %!(#5i", num);
  33.   printf("\nValue is %.4f    %s\n", num, out_str);
  34.  
  35.                                         /* Set number to convert.            */
  36.                                         /* Convert in full international fmt.*/
  37.                                         /* Print output results.             */
  38.   num = -12.6789;
  39.   strfmon(out_str, sizeof(out_str), "International format %^#.4i", num);
  40.   printf("Value is %.4f      %s\n", num, out_str);
  41.  
  42.                                         /* Set number to convert.            */
  43.                                         /* Convert in national format.       */
  44.                                         /* Print output results.             */
  45.   num = 045.6789;
  46.   strfmon(out_str, sizeof(out_str), "National format %=0#7n", num);
  47.   printf("Value is %.4f       %s\n", num, out_str);
  48. }
  49.  
  50. /*****************************************************************************/
  51. /***     Main program                                                      ***/
  52. /*****************************************************************************/
  53.  
  54. void main(void)
  55. {
  56.                                         /* Set the locale based on env var.  */
  57.                                         /* Get the locale for monetary.      */
  58.   setlocale(LC_ALL, "");
  59.   locale = setlocale(LC_MONETARY, NULL);
  60.  
  61.                                         /* Show monetary functions.          */
  62.   monetary_functs();
  63. }
  64.