FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Decimal to String
Posts: 708
Joined: Fri Oct 28, 2005 09:53 AM
Decimal to String
Posted: Thu Feb 05, 2015 06:45 PM

Hello,

This seems to be a really easy problem to solve but I cannot think of the function to handle.

I have a decimal that I want to convert to a string, for example. I want to pull the .2 from variable nVal with value of 1.2 and save as .2 not .200. I am using if I were using STR(nVal,12,3) and was wondering if there is a better solution.

*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Decimal to String
Posted: Thu Feb 05, 2015 06:55 PM
Darrell,

Code (fw): Select all Collapse
FUNCTION MAIN()

    LOCAL nVal := 1.2

    LOCAL cVal

    nVal = nVal - INT( nVal )

    ? nVal

    cVal = LTRIM( STR( nVal ) )

    ? cVal

    RETURN NIL


EMG
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Decimal to String
Posted: Thu Feb 05, 2015 07:01 PM
Or maybe:

Code (fw): Select all Collapse
FUNCTION MAIN()

    LOCAL nVal := 1.2

    LOCAL cVal := STR( nVal )

    cVal = SUBSTR( cVal, AT( ".", cVal ) )

    ? cVal

    RETURN NIL


EMG
Posts: 708
Joined: Fri Oct 28, 2005 09:53 AM
Re: Decimal to String
Posted: Mon Feb 09, 2015 03:34 PM

Dear Enrico,

Thank you. I used part of the second example you provided. I appreciate your help.

Sincerely,

*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com

Continue the discussion