Function to determine the number of decimal places?

Function to determine the number of decimal places?

Postby dpaterso » Sun Jun 17, 2007 10:20 am

Hello everyone,

Long time - no post!

I have been pulling my hair out to work this one out and I just do not seem to be able to get it right:

Is there a function that will return the number of decimal places that a number has?

Examples:

1.9873 has 4 decimal places
13.15 has 2 decimal places
9780 has 0 decimal places
655.39 has 2 decimal places

and so on and so forth.

Regards,

Dale.
dpaterso
 
Posts: 142
Joined: Tue Jan 24, 2006 9:45 am
Location: South Africa

Re: Function to determine the number of decimal places?

Postby Enrico Maria Giordano » Sun Jun 17, 2007 10:27 am

Code: Select all  Expand view
FUNCTION MAIN()

    ? NDEC( 1.9873 )
    ? NDEC( 13.15 )
    ? NDEC( 9780 )
    ? NDEC( 655.39 )

    RETURN NIL


FUNCTION NDEC( nVal )

    LOCAL cVal := STR( nVal )

    LOCAL nDec := AT( ".", cVal )

    IF nDec > 0; nDec = LEN( cVal ) - nDec; ENDIF

    RETURN nDec


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 65 guests