FormatBaseN()
Converts a number to a string, formatted in the base specified by radix.
FormatBaseN( number=number, radix=number );
Returns: String
Argument | Description |
---|---|
number
number,
required
|
Number to convert |
radix
number,
required
|
Base of the result |
Examples
<cfoutput>
#formatBaseN( 15, 2 )# <!--- 1111 (binary) --->
#formatBaseN( 15, 16 )# <!--- f (hexadecimal) --->
#formatBaseN( 15, 8 )# <!--- 17 (octal) --->
</cfoutput>
Max value limitation
Please note that the value to convert is limited to a maximum equal to java.lang.Integer.MAX_VALUE
. Values greater than this will produce unexpected results. i.e.
<cfset max = CreateObject( "java", "java.lang.Integer" ).MAX_VALUE >
<cfoutput>
#formatBaseN( max , 16 )# <!--- 7fffffff (correct) --->
#formatBaseN( max+1, 16 )# <!--- 7fffffff (incorrect) --->
</cfoutput>
See also
- Math
- Numbers
- InputBaseN()
- numeric.formatBaseN()
- Search Issue Tracker
- Search Lucee Test Cases (good for further, detailed examples)