XToC()

XToC()

Convert an expression to character type string

Syntax

       XToC( <expValue> ) --> cValue

Arguments

<expValue> Designate an expression of some of the following data type: NUMBER, CHARACTER, DATE, LOGICAL.

Returns

XToC() return a string with the representation of data type of expValue.

Description

At first glance, the XTOC() function does not appear to accomplish anything that cannot be done with the other functions. However, the advantage lies in the fact that you do not have to pay attention to the input data types. For example, you can convert the data in every field within a loop into a string. You could then link these into a longer string and use them to index or for comparisons. Each data type always returns a string with a particular fixed length:

       Each data type always returns a string with a particular fixed length:
       ----------------------------------------------------------
       Data Type Result Length    Similar function
       ---------------- --------- -------------------------------
       Numeric          8         FTOC()
       Logical          1
       Date             8         DTOS()
       String           Unchanged
       --------------- --------- -------------------------------

Examples

       .  In the case of logical parameters, XTOC() works like LTOC():
          ? XTOC(.T.)                              // "T"
          ? XTOC(.F.)                              // "F"
       .  Numeric values always return an 8-byte string:
          ? XTOC(0)                                // Length 8
          ? XTOC(9.9)                              // Ditto
          ? XTOC(-9.9)                             // Ditto
          ? XTOC(99)                               // Ditto
          ? XTOC(-99)                              // Ditto
       .  A string returns the same string:
          ? XTOC("123ABCabc")                      // "123ABCabc"
       .  A date returns the ANSI date:
          ? XTOC(CTOD("12/31/99"))                 // "19991231"
          ? XTOC(CTOD("01/01/00")                  // "19000101"
       .  An empty or false date returns an empty string rather than a
          null string:
          ? XTOC(CTOD("  /  /  ")                  // "        "
          ? XTOC(CTOD("77/77/77")                  // "        "
       .  Show a function where all the fields in a database are
          combined into one string.  This way, you can do a complete 
          comparison of the two data strings:
          // All fields in a record combined into one string
            FUNCTION STRINGREC
             PRIVATE nI, nFieldNo, cField, cStringRec
             cStringRec := ""
             nFieldNo   := FCOUNT()                // Number of fields
             FOR nI = 1 to nFieldNo
               cField          := FIELD(nI)        //  Field name
               cStringRec := cStringRec + XTOC(&cField)
             NEXT nI
             RETURN (cStringRec)

Platforms

All

Files

Source is misc1.c, library is libct.

Seealso

NTOC(), FTOC()

FTOC()

FTOC()

Converts a floating point number into a special 8-byte string

Syntax

       FTOC(<nFloatingPointNumber>) --> cFloatingPointNumber

Arguments

<nFloatingPointNumber> Designate any Clipper number.

Returns

FTOC() return a string with the size of DOUBLE.

ATTENTION: different implementations or platforms of Harbour, they could produce different format in the string returned by FTOC().

Description

Harbour internal numbers in Floating Point are stored in data type DOUBLE. FTOC() returns these bits as an string. In this way, numbers con be saved more compactly.

Note

. The XTOC() function converts floating point numbers in the same way.

Example

       It is not useful to display the return value on the screen:
           NumberString  :=  FTOC(274711.335)      // 8 byte string

Platforms

All

Files

Source is ftoc.c, library is libct.

See also

CTOF(), XTOC()

Harbour All Functions – C

CD / CHDIR / DirChange

CDoW

Chr

CharAdd
CharAnd
CharEven
CharHist
CharList
CharMirr
CharMix
CharNoList
CharNot
CharOdd
CharOne
CharOnly
CharOr
CharPix
CharRela
CharRelRep
CharRem
CharRepl
CharRLL
CharRLR
CharSHL
CharSHR
CharSList
CharSort
CharSub
CharSwap
CharWin
CharXOR

CLIPINIT
CMonth

Col

Cos

CosH

CountLeft
CountRight

CToBit

CToD

CToDoW
CToF
CToMonth
CToN

CurDir

CSetArgErr
CSetAtMuPa
CSetRef
CTCExit
CTCInit
CTExit
CTInit

Conversion Functions

Harbour Conversion Functions

Bin2I Convert signed short encoded bytes into Harbour numeric
Bin2L Convert signed long encoded bytes into Harbour numeric
Bin2U Convert unsigned long encoded bytes into Harbour numeric
Bin2W Convert unsigned short encoded bytes into Harbour numeric
BitToC Converts position-dependent bits into characters
BinToDec Converts a Binary Value to Decimal
CToBit Converts a character string into a bit pattern
CToF Converts a special 8-byte string into a floating point number
CToN Converts a numeric string into a different base
DecToBin Converts a Decimal Value to Binary
DecToHexa Converts a Decimal Value to Hexa
DecToOctal Converts a Decimal Value to Octal
Fahrenheit Temperature conversion Celsius to Fahrenheit
FToC Converts a floating point number into a special 8-byte string
HexaToDec Converts a Hexa Value to Decimal
I2Bin Convert Harbour numeric into signed short encoded bytes
L2Bin Convert Harbour numeric into signed long encoded bytes
NToC Converts the numbers in a digit string into a different number base
OctalToDec Converts a Octal Value to Decimal
U2Bin Convert Harbour numeric into unsigned long encoded bytes
W2Bin Convert Harbour numeric into unsigned short encoded bytes
Word Converts double to integer values
XTOC Convert an expression to character type string

CT_CTOF

 CTOF()
 Converts a special 8-byte string into a floating point number
------------------------------------------------------------------------------
 Syntax

     CTOF(<cFloatingPointNumber>) --> nFloatingPointNumber

 Argument

     <cFloatingPointNumber>  Designates an 8-byte character string that
     contains a Clipper number in the 64-bit floating point format.

 Returns

     CTOF() returns the number that corresponds in the passed string.

 Description

     Character strings created with FTOC() or XTOC() are changed into
     Clipper numbers.  Note that when you use XTOC(), character strings or
     portions of character strings, can be switched back, if they have been
     displayed as Clipper floating point numbers.

 Examples

     .  Change a number and then change it back:

        CTOF(FTOC(1234.55))        // Result:  1234.55

     .  This also works for XTOC():

        ? CTOF(XTOC(1234.55))      // Result:  1234.55

See Also: FTOC() XTOC()



Tools – Numbers/Bit Manipulation

Introduction
BITTOC()     Converts position-dependent bits into characters
CELSIUS()    Converts a Fahrenheit temperature value into Celsius
CLEARBIT()   Clears one or more bits within a number to zero
CTOBIT()     Converts a character string into a bit pattern
CTOF()       Converts a special 8-byte string into a floating point number
CTON()       Converts a numeric string into a different base
EXPONENT()   Determines the exponent of a floating point number (base 2)
FAHRENHEIT() Converts a temperature value from Celsius into Fahrenheit
FTOC()       Converts a floating point number into a special 8-byte string
INFINITY()   Creates the largest number possible (21023)
INTNEG()     Converts an unsigned integer into a signed integer
INTPOS()     Converts a signed integer into an unsigned integer
ISBIT()      Tests the bits in a number
LTON()       Converts a logical value into a numeric value
MANTISSA()   Determines the mantissa of a floating point number (base2)
NTOC()       Converts numbers in a digit string into a different number base
NUMAND()     Performs a 16-bit "AND" of a list of numbers
NUMCOUNT()   Uses the internal CA-Clipper Tools counter
NUMHIGH()    Returns the higher value byte in a 16-bit number
NUMLOW()     Returns the lower value byte in a 16-bit number
NUMMIRR()    Mirrors 8-bit or 16-bit values
NUMNOT()     Performs a 16-bit "NOT" of a number
NUMOR()      Performs a 16-bit "OR" of a list of numbers
NUMROL()     Performs a 16-bit left rotation of a number
NUMXOR()     Performs a 16-bit "XOR" of two numbers
RAND()       Generates random numbers
RANDOM()     Generates random numbers
SETBIT()     Sets one or more bits in a number