FormatBaseN

Converts a number to a string representation in the specified base.

Method Signature

FormatBaseN(number=[numeric], radix=[integer])

Arguments

Argument
Type
Required
Description
Default

number

numeric

true

radix

integer

true

Examples

Format 10 as dual number

Run Example

formatBaseN( 10, 2 );

Result: 1010

Format 1024 as hexadecimal number

Run Example

formatBaseN( 1024, 16 );

Result: 400

Format 125 as decimal number

Run Example

formatBaseN( 125, 10 );

Result: 125

Format a float

Floors float to integer then formats with radix given

Run Example

formatBaseN( 10.75, 2 );

Result: 1010

Additional Examples

<bx:output>
  #formatBaseN( 15, 2 )# <!--- 1111 (binary) ---> 
  #formatBaseN( 15, 16 )# <!--- f (hexadecimal) ---> 
  #formatBaseN( 15, 8 )# <!--- 17 (octal) ---> 
</bx:output>
<bx:set max = CreateObject( "java", "java.lang.Integer" ).MAX_VALUE >
<bx:output>
  #formatBaseN( max, 16 )# <!--- 7fffffff (correct) ---> 
  #formatBaseN( max + 1, 16 )# <!--- 7fffffff (incorrect) ---> 
</bx:output>

Last updated

Was this helpful?