Changeset 42


Ignore:
Timestamp:
Mar 30, 2018, 8:38:35 PM (7 years ago)
Author:
Alex Taylor
Message:

Make Sys2FormatNumber support negative values

Location:
rxutilex/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • rxutilex/trunk/rxutilex.c

    r41 r42  
    10671067 * must not contain any separators already, and any decimal point which it   *
    10681068 * contains must be a period (rather than any localized decimal symbol).     *
     1069 * The maximum value is that of a signed 64-bit integer, or a long double.   *
    10691070 *                                                                           *
    10701071 * REXX ARGUMENTS:                                                           *
     
    10811082    PSZ   pszSep = NULL;                // Thousands separator string
    10821083    PSZ   pszDec = NULL;                // Decimal point string
     1084    PSZ   pszNeg = NULL;                // Negative sign string
    10831085#ifdef LEGACY_C_LOCALE
    10841086    float fVal = 0;                     // Input value as floating point
    10851087    int   iVal;                         // Input value as integer
    10861088#else
    1087     ULONGLONG   llVal  = 0;
     1089    LONGLONG    llVal  = 0;
    10881090    long double ldVal  = 0,
    10891091                ldFrac = 0;
    1090     PSZ   p;
    1091     CHAR  achFrac[ 16 ];
    1092     int   rc     = 0;
     1092    PSZ         p,
     1093                a;
     1094    BOOL        bNeg   = FALSE;
     1095    CHAR        achFrac[ 16 ];
     1096    int         rc     = 0;
    10931097#endif
    10941098
     
    11781182    }
    11791183
     1184    // Return the formatted number
     1185    SaveResultString( prsResult, achNumber, strlen(achNumber) );
     1186
    11801187#else
    11811188
     
    11841191        // GetLocaleString has already set the error indicator
    11851192        SaveResultString( prsResult, NULL, 0 );
    1186         return ( 0 );
     1193        goto finish;
    11871194    }
    11881195    rc = GetLocaleString( &pszDec, LOCI_sDecimal );
     
    11901197        // GetLocaleString has already set the error indicator
    11911198        SaveResultString( prsResult, NULL, 0 );
    1192         return ( 0 );
    1193     }
     1199        goto finish;
     1200    }
     1201    rc = GetLocaleString( &pszNeg, LOCI_sNegativeSign );
     1202    if ( rc ) {
     1203        // GetLocaleString has already set the error indicator
     1204        SaveResultString( prsResult, NULL, 0 );
     1205        goto finish;
     1206    }
     1207
     1208    // Check for negative value
     1209    //if ( argv[0].strptr == '-') bNeg = TRUE;
    11941210
    11951211    // Check for a decimal place and treat as float or integer accordingly
     
    12071223        else
    12081224            sprintf( achFrac, "%.2Lf", ldFrac );
     1225
    12091226        // Format the integer part
    1210         GroupNumber( achNumber, llVal, pszSep );
     1227        a = achNumber;
     1228        if ( llVal < 0 ) {
     1229            sprintf( a, pszNeg );
     1230            a += strlen( pszNeg );
     1231        }
     1232        GroupNumber( a, llabs( llVal ), pszSep );
    12111233        // Append the fractional part
    12121234        if (( p = strchr( achFrac, '.')) != NULL ) {
     
    12171239    else {
    12181240        if (( sscanf( argv[0].strptr, "%lld", &llVal )) != 1 ) return ( 40 );
    1219         GroupNumber( achNumber, llVal, pszSep );
    1220     }
    1221 
    1222     free( pszSep );
     1241        a = achNumber;
     1242        if ( llVal < 0 ) {
     1243            sprintf( a, pszNeg );
     1244            a += strlen( pszNeg );
     1245        }
     1246        GroupNumber( a, llabs( llVal ), pszSep );
     1247    }
     1248
     1249    // Return the formatted number
     1250    SaveResultString( prsResult, achNumber, strlen(achNumber) );
     1251
     1252finish:
     1253    if ( pszSep ) free( pszSep );
     1254    if ( pszDec ) free( pszDec );
     1255    if ( pszNeg ) free( pszNeg );
     1256
    12231257#endif
    1224 
    1225     // Return the formatted number
    1226     SaveResultString( prsResult, achNumber, strlen(achNumber) );        // 2016-02-20 SHL
    12271258
    12281259    return ( 0 );
  • rxutilex/trunk/rxutilex.def

    r41 r42  
    11LIBRARY     RXUTILEX INITINSTANCE TERMINSTANCE
    22DATA        MULTIPLE NONSHARED
    3 DESCRIPTION '@#Alex Taylor:0.1.6#@##1## 30 Mar 2018 12:07:43     REINFORCE::::::@@Extended REXX Utility Functions'
     3DESCRIPTION '@#Alex Taylor:0.1.6#@##1## 30 Mar 2018 14:26:03     REINFORCE::::::@@Extended REXX Utility Functions'
    44
    55EXPORTS     Sys2LoadFuncs
  • rxutilex/trunk/rxutilex.txt

    r39 r42  
    169169Sys2FormatNumber
    170170
    171 Formats a number to use thousands-grouping characters.  The system values
    172 for the current locale are used for the thousands-grouping character and
    173 the decimal place, if any.  Note that the IBM C runtime's locale
    174 definitions are used; these may not correspond precisely to the system
    175 locales as defined in the OS/2 Locale object.
     171Formats a number with locale-specific thousands-grouping characters,
     172decimal point, and/or negative sign, as applicable.  The current locale
     173conventions will be used (as defined by the environment values %LC_ALL%,
     174%LC_NUMERIC%, or %LANG%, in that order of precedence).
    176175
    177176The input number may be a positive or negative integer or floating point
     
    180179point which it contains must be a period (rather than any localized
    181180decimal symbol).
     181
     182The range limits for the specified number are those of a 64-bit signed
     183integer (ñ9,223,372,036,854,775,807), or an 80-bit floating point value.
    182184
    183185REXX ARGUMENTS:
     
    496498
    497499-------------------------------------------------------------------------
     500Sys2QuerySysValue
     501
     502Query the given system value.
     503
     504REXX ARGUMENTS:
     505  1. The system value identifier  (REQUIRED)
     506     Valid identifiers are (see the Presentation Manager Programming
     507     Reference description of WinQuerySysValue for descriptions):
     508       ALARM
     509       ALTMNEMONIC
     510       ANIMATIONSPEED
     511       ANIMATION
     512       BEGINDRAG
     513       BEGINDRAGKB
     514       BEGINSELECT
     515       BEGINSELECTKB
     516       CHORDTIME
     517       CICONTEXTLINES
     518       CMOUSEBUTTONS
     519       CONTEXTHELPKB
     520       CONTEXTHELP
     521       CONTEXTMENU
     522       CONTEXTMENUKB
     523       CPOINTERBUTTONS
     524       CTIMERS
     525       CURSORLEVEL
     526       CURSORRATE
     527       CXALIGN
     528       CXBORDER
     529       CXBYTEALIGN
     530       CXCHORD
     531       CXDBLCLK
     532       CXDLGFRAME
     533       CXFULLSCREEN
     534       CXHSCROLLARROW
     535       CXHSLIDER
     536       CXICONTEXTWIDTH
     537       CXICON
     538       CXMINMAXBUTTON
     539       CXMOTIONSTART
     540       CXPOINTER
     541       CXSCREEN
     542       CXSIZEBORDER
     543       CXVSCROLL
     544       CYALIGN
     545       CYBORDER
     546       CYBYTEALIGN
     547       CYCHORD
     548       CYDBLCLK
     549       CYDLGFRAME
     550       CYFULLSCREEN
     551       CYHSCROLL
     552       CYICON
     553       CYMENU
     554       CYMINMAXBUTTON
     555       CYMOTIONSTART
     556       CYPOINTER
     557       CYSCREEN
     558       CYSIZEBORDER
     559       CYTITLEBAR
     560       CYVSCROLLARROW
     561       CYVSLIDER
     562       DBLCLKTIME
     563       DEBUG
     564       ENDDRAG
     565       ENDDRAGKB
     566       ENDSELECTKB
     567       ENDSELECT
     568       ERRORDURATION
     569       ERRORFREQ
     570       FIRSTSCROLLRATE
     571       INSERTMODE
     572       KBDALTERED
     573       LOCKSTARTINPUT
     574       MENUROLLDOWNDELAY
     575       MENUROLLUPDELAY
     576       MONOICONS
     577       MOUSEPRESENT
     578       NOTEDURATION
     579       NOTEFREQ
     580       NUMBEREDLISTS
     581       OPEN
     582       OPENKB
     583       POINTERLEVEL
     584       PRINTSCREEN
     585       SCROLLRATE
     586       SELECTKB
     587       SETLIGHTS
     588       SINGLESELECT
     589       SWAPBUTTON
     590       TASKLISTMOUSEACCESS
     591       TEXTEDIT
     592       TEXTEDITKB
     593       TRACKRECTLEVEL
     594       WARNINGDURATION
     595       WARNINGFREQ
     596
     597REXX RETURN VALUE:
     598  String containing the requested system value, or "" in case of error.
     599
     600
     601-------------------------------------------------------------------------
    498602Sys2Read
    499603
  • rxutilex/trunk/testlib.cmd

    r41 r42  
    5353
    5454say Sys2FormatNumber('9375739912303')
    55 say Sys2FormatNumber('64583.449286', 5)
     55say Sys2FormatNumber('-64583.449286', 5)
    5656
    5757
Note: See TracChangeset for help on using the changeset viewer.