FormatPercent ( Number ; Decimals )
Rate this function: Average rating: 4.5 (37 votes) Discuss this Custom Function
Will Loving, Dedication Technologies, Inc.
http://dedicationtechnologies.com
Formats a number as a percentage text string with specified number of decimal places
Sample Input:
FormatPercent ( .4587 ; 1 ) 

Sample Output:

Description:
Formats a number value as a percentage in a text string with the specified number of decimal places, from 0 to 10. Useful for calculated text strings that need to include a formatted percentage.
17 Jan 2011  modified to address issue noted by Jeremiah Hammond.
Note: these functions are not guaranteed
or supported by BrianDunning.com. Please contact the individual
developer with any questions or problems.
This is my Custom Function and I want to
edit it
Discuss:Make a comment about this Custom Function (please try to keep it brief & to the point). Anyone can post:

Newest Custom Functions:
1. 
ChiSquare3x2 ( param ; param ; param ; param ) 

(Tue, Aug 14, 6:33am) 
2. 
ReverseByteOrder ( bytes ) 

(Thu, Aug 09, 12:06pm) 
3. 
BytesToDec ( hex ) 

(Thu, Aug 09, 11:47am) 
4. 
GetAsHexBytes ( number ; bytes ) 

(Thu, Aug 09, 10:50am) 
5. 
ValCorrelationCoeff ( XValueList; YValueList; Xmean; Ymean; XStdDev; YStdDev ) 

(Wed, Aug 08, 4:17pm) 
6. 
ValLeastSquaresSlope ( XValueList; YValueList; Xmean; Ymean ) 

(Wed, Aug 08, 4:10pm) 
7. 
ValueMath ( List1 ; List2 ; operation ) 

(Wed, Aug 08, 4:05pm) 
8. 
GetExtension ( File ) 

(Tue, Aug 07, 10:22am) 


The current version (as of 01/17/2011) fails with the following input: FormatPercent( .1304 ; 1 ). It'll return 1300% instead of 13.0%. The issue has to do with the ending case statement, where the rounded percent  integer of the rounded percentage happens to equal 0, instead of some decimal (say: 13.0  13). The function will attach zeros to the whole number portion of the percentage without a decimal.
Here's a fixed version of the function:
Case ( Decimals = 0 or IsEmpty ( Decimals ) ; Int ( Round ( Number * 100 ; 0 ) ) ;
Int ( Round( Number * 100 ; Decimals ) ) &
Case ( ( Number * 100 ) = Int ( Number * 100 ) ; Left ( ".0000000000" ; Decimals + 1 ) ;
Round ( Number * 100 ; Decimals )  Int( Round ( Number * 100 ; Decimals ) ) = 0 ; Left ( ".0000000000" ; Decimals + 1 ) ;
Left ( Round ( Number * 100 ; Decimals )  Int( Round ( Number * 100 ; Decimals ) ) & "0000000000" ; Decimals+1 ) ) )
& "%"
Jeremiah Hammond, Indianapolis
January 17, 2011 2:09am